I can run the following shell script from command prompt as expected:
/bin/sh -xv /home/shantanu/backup_transfer.sh
But when I set it in a cron, it does not execute correctly. There are 2 commands. ssh -t abc@10.10.10.100 "sudo ls" and sudo rsync -avze to another server.
Why would a shell script fail in a cron when it runs successfully at command prompt?
$ which sh
/bin/sh
Am I using the correct environment?
Update:
Error for the first ssh -t command:
Pseudo-terminal will not be allocated because stdin is not a terminal.
sudo: sorry, you must have a tty to run sudo
Error for the second sudo rsync command:
sudo: sorry, you must have a tty to run sudo
No error while running the script at command prompt.
sudo
? Did you configure with passwordless?command >> /tmp/log 2>&1
-t
or edit your/etc/sudoers
file with something like thisDefaults:abc !requiretty
. Why didn't you search the above error in this site?