I have two bash scripts. One runs as root, and it calls another one as user "parallels"
/root/cronrun.sh
#! /bin/bash
PARR="thisparameter"
echo "Starting at `date`" >> /root/rlog.log
runuser -l parallels -c "/home/parallels/testscript/newscript.sh $PARR"
echo "Finishing at `date`" >> /root/rlog.log
/home/parallels/testscript/newscript.sh
#! /bin/bash
PARAMM=$1
echo "`date` - newscript.sh ran with $PARAMM" >> /home/parallels/somelog.log
Ran /root/cronrun.sh from command line as root at
18:17:28 CET
18:17:29 CET
Added to crontab
*/2 * * * * /root/cronrun.sh
So it ran at 18:20:00 CET via cron
After this:
/root/rlog.log
Starting at Thu Nov 16 18:17:28 CET 2017
Finishing at Thu Nov 16 18:17:28 CET 2017
Starting at Thu Nov 16 18:17:29 CET 2017
Finishing at Thu Nov 16 18:17:29 CET 2017
Starting at Thu Nov 16 18:20:01 CET 2017
Finishing at Thu Nov 16 18:20:01 CET 2017
/home/parallels/somelog.log
Thu Nov 16 18:17:28 CET 2017 - newscript.sh ran with thisparameter
Thu Nov 16 18:17:29 CET 2017 - newscript.sh ran with thisparameter
So the log entry from the echo in the runuser shell is missing. Why it can be possible? How does cron run differently in this case, which makes "runuser" command ignored/failed?
(System reproduced on is Ubuntu 16.04.3 LTS)
(SHELL=/bin/bash in crontab is not solving it)
runuser
in it, while your interactive shell does?