System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

script run ok manually but failed when run as a cronjob

Fenglin
Regular Advisor

script run ok manually but failed when run as a cronjob

Hi

I write the script,ftp_stats.sh below

#!/usr/bin/ksh

/usr/bin/ftp -i -n < ftp_stats.txt
-------------------------------------------
ftp_stats.txt is as follows
open IPaddress
user id password
cd dataload
put stats.log

The objective is to run the job as a cron successfully.

Please advice.

Regards
Feng Lin
Please advice.
14 REPLIES
R.K. #
Honored Contributor

Re: script run ok manually but failed when run as a cronjob

Hi Fenglin,

How do you run the script manually?

Because the script contains "cd" command, I guess that might be a issue.

The script containing "cd" have to be run bit differently as far as I know.
Don't fix that what ain't broke
Michal Kapalka (mikap)
Honored Contributor

Re: script run ok manually but failed when run as a cronjob

hi,

could you send the line from crontab ??

mikap
Johnson Punniyalingam
Honored Contributor

Re: script run ok manually but failed when run as a cronjob

what doesn cron.log shows ?
Problems are common to all, but attitude makes the difference
Fenglin
Regular Advisor

Re: script run ok manually but failed when run as a cronjob

Hi All

34 12 * * 1-5 /root/ftp_nspay_stats.sh > /dev/null 2>&1

cron.log shows

CMD: /root/ftp_stats.sh > /dev/null 2>&1
> root 18598 c Thu Dec 17 12:34:00 SST 2009

Regards
Feng Lin

Re: script run ok manually but failed when run as a cronjob

Why don't you remove "> /dev/null 2>&1" from the command so you can see the error message?
Johnson Punniyalingam
Honored Contributor

Re: script run ok manually but failed when run as a cronjob

ls -l /root/ftp_nspay_stats.sh

also make sure you have rwx -permissions ?
Problems are common to all, but attitude makes the difference
Michal Kapalka (mikap)
Honored Contributor

Re: script run ok manually but failed when run as a cronjob

hi,

you could define a dhell before the sh script in the cron.

/usr/bin/ksh /path_to_the_scrit.sh

mikap
Fenglin
Regular Advisor

Re: script run ok manually but failed when run as a cronjob

Hi All

The error message is

Connected to IP address.
220 IP address FTP server (Revision 1.1 Version wuftpd-2.6.1(PHNE_36065) Mon Apr 14 06:17:08 GMT 2008) ready.
Remote system type is UNIX.
Using binary mode to transfer files.
331 Password required for email.
230 User email logged in.
250 CWD command successful.
nspay_stats.log: No such file or directory
221-You have transferred 0 bytes in 0 files.
221-Total traffic for this session was 341 bytes in 0 transfers.
221-Thank you for using the FTP service on IP address.
221 Goodbye.

Any resolution? Please note that when I run manually, it works fine.

Regards
Feng Lin

Re: script run ok manually but failed when run as a cronjob

In your original post the filename was "stats.log", but the error references "nspay_stats.log". I assume the second one is the correct filename?

Most likely the script is not being run from the directory you think it io. You can confirm that by executing "pwd" at the top of the script. If that's the problem, just add "cd /some/dir" before the ftp command. (Where "/some/dir" is the location of nspay_stats.log.)
Jeeshan
Honored Contributor

Re: script run ok manually but failed when run as a cronjob

For cron job run application, you have to mention the full path of the source or destination file or folder.

where is your ftp_stats.txt file or is dataload is correct? or what is the absolute path of stats.log?

put all absolute file path and check.
a warrior never quits
Michal Kapalka (mikap)
Honored Contributor

Re: script run ok manually but failed when run as a cronjob

hi,

define the full path from /.../.../stats.log,

in you script.

mikap
Michal Kapalka (mikap)
Honored Contributor

Re: script run ok manually but failed when run as a cronjob

hi,

full path = absolute path.

mikap
Fenglin
Regular Advisor

Re: script run ok manually but failed when run as a cronjob

Hi River tarnell

Thanks for your reply. My problem is solved.

Cheers
Feng Lin
Jeeshan
Honored Contributor

Re: script run ok manually but failed when run as a cronjob

Nice to hear that the problem is solved.

You can now assign points to participants and close the thread. This might help you to get answer in prompt.
a warrior never quits