Operating System - HP-UX
1825803 Members
2511 Online
109687 Solutions
New Discussion

Cron can't executes the ftp script

 
ashanabey
Advisor

Cron can't executes the ftp script

Hi,

I am trying to run an ftp job in root cron and I can see in the log it executes but script not doing the job.

Below is the script and cron log too


#!/usr/bin/ksh
HOST='ftp.abc.com'
USER='abcftp'
PASSWD='nzm6hxip'

/usr/bin/ftp -ni $HOST <quote USER $USER
quote PASS $PASSWD
bin
cd /tpadepot
put RECON_AMIC_20080207.DAT
quit
END_SCRIPT
exit 0


abc1:/var/spool/cron/crontabs #cd /var/adm/cron
abc1:/var/adm/cron #tail -f log
< root 17793 c Fri Feb 8 15:25:05 EST 2008
> CMD: /cl-01/apps/wcis/wcisclon/output/ftpjob.ksh > /dev/null 2>&1
> root 18317 c Fri Feb 8 15:27:00 EST 2008
< root 18317 c Fri Feb 8 15:27:05 EST 2008
> CMD: /scripts/CLEAN_VAR_TMP > /dev/null 2>&1
> root 19454 c Fri Feb 8 15:35:00 EST 2008
< root 19454 c Fri Feb 8 15:35:00 EST 2008 rc=126
> CMD: /cl-01/apps/wcis/wcisclon/output/ftpjob.ksh
> root 22028 c Fri Feb 8 15:55:00 EST 2008
< root 22028 c Fri Feb 8 15:55:05 EST 2008

Any one has a idea.

Thx!

Ashan
legend the heart and lend the hand
4 REPLIES 4
Paul Sperry
Honored Contributor

Re: Cron can't executes the ftp script

I use the .netrc

machine ServerName
login UserName
password Password
macdef init
lcd /some/local/path
cd /some/remote/path
put localfile remotefile
quit

then in cron
00 01 * * * /usr/bin/ftp Servername > /dev/null 2>&1
OldSchool
Honored Contributor

Re: Cron can't executes the ftp script

fix your job so that it:

switches on verbose ftp messages and
logs the output to a file.

from what you've given, it could be anything.

ftp -v -niv 2>&1 > /logfile <<-END
.
.
.
END

or in the crontab entry, something like

your_command 2>&1 > /logfile

then examine logfile
Dennis Handly
Acclaimed Contributor

Re: Cron can't executes the ftp script

Any reason you are using quote?
Typically you use:
ftp -ni $HOST <user $USER:$PASSWD
...
Bill Hassell
Honored Contributor

Re: Cron can't executes the ftp script

In your script:

> #!/usr/bin/ksh
> HOST='ftp.abc.com'
> USER='abcftp'
> PASSWD='nzm6hxip'

Using apostrophes is not necessary as there are no special characters in the string.

> /usr/bin/ftp -ni $HOST <> quote USER $USER
> quote PASS $PASSWD

Using quote in this context is not necessary or even recommended. Put everything on a single line:

USER $USER $PASSWD

> bin
> cd /tpadepot
> put RECON_AMIC_20080207.DAT

There is the likely problem. You issued a remote cd command but never issued a local lcd command. Therefore, your current working directory is your $HOME directory (see man crontab). Always use lcd. And when running anything in cron, always use a logfile with -v options to any commands in your cron jobs.


Bill Hassell, sysadmin