Skip to main content
deleted 3 characters in body
Source Link
Mark Plotnick
  • 26k
  • 3
  • 68
  • 82

Your ultimate problem was that mailx, when called from a shell script run by smartd, started by systemd, on Arch Linux, was not reading the root user's $HOME/.mailrc file.

This was caused by a few factors:

  • The mailx on Arch Linux, s-nail, relies on the environment variable HOME when looking for the .mailrc file. If HOME isn't present, it uses the current working directory.
  if ((cp = getenv("HOME")) == NULL)
      cp = "."; /* XXX User and Login objects; Login: pw->pw_dir */
  homedir = savestr(cp); 

$USER, $LOGNAME, $HOME, $SHELL

User name (twice), home directory, and the login shell. The variables are set for the units that have User= set, which includes user systemd instances.

Since there was no HOME variable in the environment provided to smartd, and it was likely started in the / directory, mailx couldn't find adidn't read the $HOME/root/.mailrc to readfile.

WorkaroundTo fix: add the line

export HOME=~

or

export MAILRC=~/.mailrc

to the shell script before it invokes mailx

or (untestednot tested by me) add

User=root

to the [Service] stanza of your smartd.service unit configuration file.

Your ultimate problem was that mailx, when called from a shell script run by smartd, started by systemd, on Arch Linux, was not reading the root user's $HOME/.mailrc file.

This was caused by a few factors:

  • The mailx on Arch Linux, s-nail, relies on the environment variable HOME when looking for the .mailrc file. If HOME isn't present, it uses the current working directory.
  if ((cp = getenv("HOME")) == NULL)
      cp = "."; /* XXX User and Login objects; Login: pw->pw_dir */
  homedir = savestr(cp); 

$USER, $LOGNAME, $HOME, $SHELL

User name (twice), home directory, and the login shell. The variables are set for the units that have User= set, which includes user systemd instances.

Since there was no HOME variable in the environment provided to smartd, and it was likely started in the / directory, mailx couldn't find a $HOME/.mailrc to read.

Workaround: add the line

export HOME=~

or

export MAILRC=~/.mailrc

to the shell script before it invokes mailx

or (untested by me) add

User=root

to the [Service] stanza of your smartd.service unit configuration file.

Your ultimate problem was that mailx, when called from a shell script run by smartd, started by systemd, on Arch Linux, was not reading the root user's $HOME/.mailrc file.

This was caused by a few factors:

  • The mailx on Arch Linux, s-nail, relies on the environment variable HOME when looking for the .mailrc file. If HOME isn't present, it uses the current working directory.
  if ((cp = getenv("HOME")) == NULL)
      cp = "."; /* XXX User and Login objects; Login: pw->pw_dir */
  homedir = savestr(cp); 

$USER, $LOGNAME, $HOME, $SHELL

User name (twice), home directory, and the login shell. The variables are set for the units that have User= set, which includes user systemd instances.

Since there was no HOME variable in the environment provided to smartd, and it was likely started in the / directory, mailx didn't read the /root/.mailrc file.

To fix: add the line

export HOME=~

or

export MAILRC=~/.mailrc

to the shell script before it invokes mailx

or (not tested by me) add

User=root

to the [Service] stanza of your smartd.service unit configuration file.

Source Link
Mark Plotnick
  • 26k
  • 3
  • 68
  • 82

Your ultimate problem was that mailx, when called from a shell script run by smartd, started by systemd, on Arch Linux, was not reading the root user's $HOME/.mailrc file.

This was caused by a few factors:

  • The mailx on Arch Linux, s-nail, relies on the environment variable HOME when looking for the .mailrc file. If HOME isn't present, it uses the current working directory.
  if ((cp = getenv("HOME")) == NULL)
      cp = "."; /* XXX User and Login objects; Login: pw->pw_dir */
  homedir = savestr(cp); 

$USER, $LOGNAME, $HOME, $SHELL

User name (twice), home directory, and the login shell. The variables are set for the units that have User= set, which includes user systemd instances.

Since there was no HOME variable in the environment provided to smartd, and it was likely started in the / directory, mailx couldn't find a $HOME/.mailrc to read.

Workaround: add the line

export HOME=~

or

export MAILRC=~/.mailrc

to the shell script before it invokes mailx

or (untested by me) add

User=root

to the [Service] stanza of your smartd.service unit configuration file.