0

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?

Socrates
  • 2,473

1 Answers1

0

"No MTA installed" means that in your script, you might want to send an email, but no MTA (Mail Transfer Agent) have been specified. The cron daemon tries in fact to send outputs to you. You can install an MTA (like postfix), or, if outputs are not important, redirect to" /dev/null 2>&1"

limace255
  • 131
  • Ok, just created a script that calls the other script, but mutes all the output to > /dev/null 2>&1. Running it manually works, running it through Crontab after reboot fails. – Socrates May 23 '16 at 10:35
  • Oh.And if you add "> /dev/null 2>&1" directl in your crontab ? – limace255 May 23 '16 at 11:43
  • Shouldn't make any difference, as it is still a command run by Crontab... Ok, just tried it. Same result. I believe the problem is elsewhere. I think there must be a place where a loaded key is stored as soon as there has been one login. All the next logins check that key instead of re-loggin-in everytime. Could that be right? – Socrates May 23 '16 at 21:01
  • What I propose to you is to remove everything that can be : 1/ edit your crontab to be run directly by your user (you should have something like : 45 10 * * * my_user bash my-local-script) 2/ modify your script, removing 'ssh' options ( "-i" will be automatically done, etc) 3/ Be sure that you can 'ssh' without being prompted for anything, when you're connected with 'my_user' account, if not renew ssh-keygen ('ssh-keygen -R servername').Is it possible to share your script somewhere ? – limace255 May 24 '16 at 06:20