Operating System - HP-UX
1753960 Members
7541 Online
108811 Solutions
New Discussion юеВ

Re: 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 14
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 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
River Tarnell
Advisor

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
River Tarnell
Advisor

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.)