I am regularly running a shell script through Crontab that uses SSH to connect to a server. If I run that script manually it runs through successfully. Within the same session Crontab will successfully run it, too. But if I restart my machine and wait for Crontab to start the script, then it fails.
My machine and the server I connect to both have keys without password of each other.
SSH-command in my script:
ssh -i /home/myuser/.ssh/id_rsa -t -t myuser@servername 'some-script-on-the-server'
Crontab-command:
45 10 * * * root sudo -u myuser my-local-script
I thought I'd solve this issue by providing the SSH command with -i /home/myuser/.ssh/id_rsa
but this did it still did not work after that.
The output of /var/log/syslog
is:
May 23 11:06:01 mycomputer CRON[1254]: (root) CMD (sudo -u myuser my-local-script)
May 23 11:06:01 mycomputer CRON[1252]: (CRON) info (No MTA installed, discarding output)
What's the problem?
myuser
instead ofroot
and putting awaysudo -u myuser
. Didn't change a thing concerning the above mentioned problem though. – Socrates May 23 '16 at 09:32