1

I have a script with following line

sshpass -p 'password' ssh user@server "touch /tmp/test"

this works, when I run the script, but if I put the script in cron it doesen't work. any ideas ?

him
  • 111
  • 1
  • 10
  • What does the cron entry look like? Are you putting it in your own, root's crontab (using sudo) of that of some other user? – jDo Apr 14 '16 at 23:45
  • Is it getting an error? Any output from the cron job should be sent to you as email (I hope you're not redirecting the output to /dev/null). – Barmar Apr 14 '16 at 23:57

2 Answers2

5

Since this is the first answer on google, give sshpass absolute path like /usr/bin/sshpass. you can get the path by which sshpass. I also added /usr/bin/ssh to be sure.

rcpfuchs
  • 792
  • 1
  • 12
  • 26
4

It worked after adding -o StrictHostKeyChecking=no

sshpass -p 'password' ssh -o StrictHostKeyChecking=no user@server "touch /tmp/test" 
him
  • 111
  • 1
  • 10