Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cron job not running

Status
Not open for further replies.

fid

Programmer
May 10, 2001
20
US
Hi,

I have a script that i want to run daily
i placed the script in /etc/cron.daily/ (as root)

the script launches an expect script which connects to a remote server via sftp2
the secure shell requires a user interactive password to be entered, so expect script is the only way i could think of to accomplish this task automatically

if i run the script by itself, it runs perfectly
the problem is it won't run from cron.daily or crontab entry
i've tried everything, help!


/etc/cron.daily/lograbber
#!/bin/sh

/home/ `date --date=yesterday +%Y
%m%d`


heres what the lograbber.exp script looks like:

#!/usr/bin/expect -f
set force_conservative 0
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} { sleep .1
exp_send -s -- $arg }
}

set filedate [lindex $argv 0];

set timeout -1
spawn /home/ user@123.123.123.123
match_max 100000
expect -exact "user@123.123.123.123's password:"
send -- "xxxxxxx\r"
expect -exact "sftp>"
send -- "cd /logs/archive\r"
expect -exact "sftp>"
send -- "lcd /logs/archive\r"
expect -exact "sftp>"
send -- "get mywebsite.$filedate.zip\r"
expect -exact "sftp>"
send -- "quit\r"
spawn /usr/bin/zip -d /logs/archive/mywebsite.$filedate.zip \*error\*
expect eof
 
First, I think the issue with the script is that you may not have made it executable?!!

Second, and more important/useful, is that you should be using Public Key Authentication, which will bypass a lot of the nonsense in your script.

PKA is used by generating a "key" file using SSH on your machine and then you securely copy that file to the destination/other machine. With that key/user in place you are able to log into the other machine using SSH without a password dialog requiring input. You drop straight to a prompt on the other machine.

HTH.

 
Hi,

sometimes its a problem in the environment.
If you start locally all variables are set, but in cron they are not set. You must set all neccesary variablesin the script by working from cron

hth
Uwe
 
... and cron could be using a cache, and not recognizing a modified entry. My version of cron forces me to use 'crontab -e' to edit the crontab. It's not needed for /etc/cron.daily/FILES on my system, but systems may differ...

seeking a job as java-programmer in Berlin:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top