Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
Does these commands require sudo? Did you configure with passwordless? –  quanta Nov 21 '11 at 3:07
    
Yes. it works as expected from command prompt. it is passwordless copy to remote server. –  shantanuo Nov 21 '11 at 3:13
1  
1. Always use the absolute path when doing something in cron. 2. Redirect both of error and output to a log file to see what happens command >> /tmp/log 2>&1 –  quanta Nov 21 '11 at 3:29
    
question updated with error out info. –  shantanuo Nov 21 '11 at 3:46
1  
Use double -t or edit your /etc/sudoers file with something like this Defaults:abc !requiretty. Why didn't you search the above error in this site? –  quanta Nov 21 '11 at 3:52
add comment

1 Answer

up vote 2 down vote accepted

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
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.