Register
It is currently Sun Dec 21, 2014 11:56 pm

Script runs if executed from CL, not from Cron


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Wed Oct 13, 2010 3:47 am   

Joined: Fri May 07, 2010 4:04 am
Posts: 7
Hi,
I am having this script:
Code:
HOST="***.***.***.***"
USER="***"
PASS="***"

EXEC=$(expect -c "
spawn sftp -o \"BatchMode no\" -b /home/portal/bin/xymon-backup-cmd $USER@$HOST
expect \"password:\"
send \"$PASS\r\"
interact
")

echo "$EXEC"


cd /var/www/html/xymon-backup

mv bb-hosts bb-hosts_`date -I`


xymon-backup-cmd has the following commands in it:
Code:
lcd /var/www/html/xymon-backup
cd server/etc
get bb-hosts
exit


If I run it from the CL, it works and it saves the bb-hosts file to the "/var/www/html/xymon-backup" dir.
But if run by cron, it does not work.

Could you help me please?

Thank you.
George.


Top
 Profile  
 PostPosted: Thu Oct 14, 2010 1:58 pm   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
What do you mean by "does not work"? Does the script get executed at all from cron? Some of the possible problems: Do not call your variable USER, it is special to bash. I am not sure cron knows the path to your commands, you might need to set PATH or use full paths.


Top
 Profile  
 PostPosted: Thu Oct 14, 2010 8:19 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 673
Location: Des Moines, Iowa
I agree.

1. Don't call any of your variables $USER
2. give the FULL paths to executables in your script.

Do that then report back :)


Top
 Profile WWW  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP