Skip to main content
added 1161 characters in body
Source Link
DominicM
  • 699
  • 3
  • 15
  • 26

I have created a script that smartd daemon (smartmontools) executes as per command below.

DEVICESCAN -a -m email -M test -M exec /usr/share/smartmontools/my-script -n stand...

Smartd appears to be running as root looking at the top command output but it fails to find a config file in /root. $USER, $HOME, whoami, export USER=$(id -u -n) commands do not echo anything, not even an empty line. When executed manually in terminal it prints the current username as expected. Script was chmod'ed to 700.

Why is this happening?

Edit: Here is the actual script that I want to run.

#!/bin/sh

export USER=$(id -u -n)
echo $whoami
echo "USER: "
echo "$USER"
echo $HOME

EMAIL_EXEC="mailx"
EMAIL_ACCOUNT="gmail"
EMAIL_SUBJECT="simplified"
EMAIL_BODY="simplified"

echo "$EMAIL_BODY " | $EMAIL_EXEC -A $EMAIL_ACCOUNT -s "$EMAIL_SUBJECT" [email protected]

After restarting smartd errors are found in the log and no email is sent unlike if executed manually as root.

sudo systemctl restart smartd
journalctl -u smartd

Here is the output of journalctl log:

Test of /etc/smartmontools/run.d/email to [email protected] produced unexpected output (69 bytes) to STDOUT/STDERR:
USER:
root
Account `gmail' does not exist.
No mail for root

export USER=$(id -u -n) appears to have set the $USER variable as you mentioned. "gmail" is a profile in /root/.mailrc file. Same error is produced when running as non-root user because the .mailrc file is missing in users home.

How can I set the $HOME variable like the $USER variable? That might give an idea why it's not finding the file.

I have created a script that smartd daemon (smartmontools) executes as per command below.

DEVICESCAN -a -m email -M test -M exec /usr/share/smartmontools/my-script -n stand...

Smartd appears to be running as root looking at the top command output but it fails to find a config file in /root. $USER, $HOME, whoami, export USER=$(id -u -n) commands do not echo anything, not even an empty line. When executed manually in terminal it prints the current username as expected. Script was chmod'ed to 700.

Why is this happening?

I have created a script that smartd daemon (smartmontools) executes as per command below.

DEVICESCAN -a -m email -M test -M exec /usr/share/smartmontools/my-script -n stand...

Smartd appears to be running as root looking at the top command output but it fails to find a config file in /root. $USER, $HOME, whoami, export USER=$(id -u -n) commands do not echo anything, not even an empty line. When executed manually in terminal it prints the current username as expected. Script was chmod'ed to 700.

Why is this happening?

Edit: Here is the actual script that I want to run.

#!/bin/sh

export USER=$(id -u -n)
echo $whoami
echo "USER: "
echo "$USER"
echo $HOME

EMAIL_EXEC="mailx"
EMAIL_ACCOUNT="gmail"
EMAIL_SUBJECT="simplified"
EMAIL_BODY="simplified"

echo "$EMAIL_BODY " | $EMAIL_EXEC -A $EMAIL_ACCOUNT -s "$EMAIL_SUBJECT" [email protected]

After restarting smartd errors are found in the log and no email is sent unlike if executed manually as root.

sudo systemctl restart smartd
journalctl -u smartd

Here is the output of journalctl log:

Test of /etc/smartmontools/run.d/email to [email protected] produced unexpected output (69 bytes) to STDOUT/STDERR:
USER:
root
Account `gmail' does not exist.
No mail for root

export USER=$(id -u -n) appears to have set the $USER variable as you mentioned. "gmail" is a profile in /root/.mailrc file. Same error is produced when running as non-root user because the .mailrc file is missing in users home.

How can I set the $HOME variable like the $USER variable? That might give an idea why it's not finding the file.

deleted 13 characters in body
Source Link
DominicM
  • 699
  • 3
  • 15
  • 26

I have created a script that smartd daemon (smartmontools) executes as per command below.

DEVICESCAN -a -m email -M test -M exec /usr/share/smartmontools/my-script -n stand...

Smartd appears to be running as root looking at the top command output but it fails to find a config file in /root. $USER, $HOME, whoami, export USER=$(id -u -n) commands do not echo anything, not even an empty line. When executed manually in terminal it prints the current username as expected. Both scripts have been Script was chmod'ed to 700.

Why is this happening?

I have created a script that smartd daemon (smartmontools) executes as per command below.

DEVICESCAN -a -m email -M test -M exec /usr/share/smartmontools/my-script -n stand...

Smartd appears to be running as root looking at the top command output but it fails to find a config file in /root. $USER, $HOME, whoami, export USER=$(id -u -n) commands do not echo anything, not even an empty line. When executed manually in terminal it prints the current username as expected. Both scripts have been chmod'ed to 700.

Why is this happening?

I have created a script that smartd daemon (smartmontools) executes as per command below.

DEVICESCAN -a -m email -M test -M exec /usr/share/smartmontools/my-script -n stand...

Smartd appears to be running as root looking at the top command output but it fails to find a config file in /root. $USER, $HOME, whoami, export USER=$(id -u -n) commands do not echo anything, not even an empty line. When executed manually in terminal it prints the current username as expected. Script was chmod'ed to 700.

Why is this happening?

deleted 386 characters in body
Source Link
DominicM
  • 699
  • 3
  • 15
  • 26

I am runninghave created a smartd-runner script that user run-parts to execute all scripts in a given directory. This script is in turn executed by smartd daemon of smartmontools. It appears to be running(smartmontools) executes as root looking at the topper command outputbelow.

#!/bin/bash

tmp=tempfile
cat >$tmp

run-partsDEVICESCAN --reporta --lsbsysinitm --arg=$tmpemail --arg="$1"M \
--arg="$2"test --arg="$3"M --exec /etcusr/share/smartmontools/run.d

rmmy-script -fn $tmpstand...

The issue is that it does not in practice runSmartd appears to be running as root or in fact as any other user that I can tell. There is onlylooking at the top command output but it fails to find a single scriptconfig file in run.d directory/root. That script prints the $USER variable an, $HOME, whoami, export USER=$(id -u -n) commands do not echo anything, not even an empty line. When executed manually in terminal it prints the current username. When the smartd-runner script is executed by smartd it prints nothing for the $USER variable or whoami, not even a empty line thought it does print literal strings like echo "user:" as expected. Both Both scripts have been chmod'ed to 700.

Why is this happening?

I am running a smartd-runner script that user run-parts to execute all scripts in a given directory. This script is in turn executed by smartd daemon of smartmontools. It appears to be running as root looking at the top command output.

#!/bin/bash

tmp=tempfile
cat >$tmp

run-parts --report --lsbsysinit --arg=$tmp --arg="$1" \
--arg="$2" --arg="$3" -- /etc/smartmontools/run.d

rm -f $tmp

The issue is that it does not in practice run as root or in fact as any other user that I can tell. There is only a single script in run.d directory. That script prints the $USER variable an whoami. When executed manually it prints the current username. When the smartd-runner script is executed by smartd it prints nothing for the $USER variable or whoami, not even a empty line thought it does print literal strings like echo "user:". Both scripts have been chmod'ed to 700.

Why is this happening?

I have created a script that smartd daemon (smartmontools) executes as per command below.

DEVICESCAN -a -m email -M test -M exec /usr/share/smartmontools/my-script -n stand...

Smartd appears to be running as root looking at the top command output but it fails to find a config file in /root. $USER, $HOME, whoami, export USER=$(id -u -n) commands do not echo anything, not even an empty line. When executed manually in terminal it prints the current username as expected. Both scripts have been chmod'ed to 700.

Why is this happening?

deleted 30 characters in body
Source Link
DominicM
  • 699
  • 3
  • 15
  • 26
Loading
Source Link
DominicM
  • 699
  • 3
  • 15
  • 26
Loading