Cron – shell script within crontab

cronshell

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.

Best Answer

To correct the sudo tty error you need to modify the /etc/sudoers file on the host that you are issuing the sudo command on.

#Here is an example of how to turn off the requirement of a tty for a user called "USERNAME"
Defaults:USERNAME !requiretty
Related Topic