HPE 9000 and HPE e3000 Servers
1748787 Members
3209 Online
108766 Solutions
New Discussion юеВ

Re: ftp in cron fails, from command works OK

 
Ragu_5
Occasional Contributor

ftp in cron fails, from command works OK

Hi
Attaching a shell script which works OK from command line but not in cron. It is just the ftp piece which is failing. Can you please help. TIA
Ragu

Script to send email on the DBA Aud files
#
#
#############################################
#!/usr/bin/ksh
set -x
dtenum=`date +%m%d%y`
integer wknum=$dtenum/7
echo $wknum

check_stat=`/usr/bin/find /u01/oracle/admin/fidev/audit -name "*.aud" -exec ls -
l {} \; | wc -l`;
echo $check_stat

orcl=`expr $check_stat`

if [ $orcl -ge 2 ]
then

else
1/oracle/admin/fidev/audit -name "*.aud"`
echo "no Audit file present"o" test@mydomain.com,test2@mydomain.com < /
01/oracle/admin/fidev/audit/edf$dtenum.tar
fi
a1.sh (70%)
echo "FTPing...."

/usr/bin/ftp -n hulk << EOF

user corp/\ragu test

cd /group/it/sox/midas/

bin

mput *.tar

bye

EOF

#/usr/bin/find /u01/oracle/admin/fidev/audit -name "*.aud" -exec rm {} \;
#
8 REPLIES 8
Jeff Schussele
Honored Contributor

Re: ftp in cron fails, from command works OK

Hi Ragu,

I suspect the problem is due to the very sparse environment that a cron session receives.
Try sourcing the appropriate user's .profile early in the script to insure you have an equivalent environment that you'd have in a shell session. All cron scripts should really do this.

HTH,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Ivan Ferreira
Honored Contributor

Re: ftp in cron fails, from command works OK

Instead of using << EOF, try this:

echo "user username password
cd /group/it/sox/midas/
bin
mput *.tar
bye" | ftp -i -n hulk
Por que hacerlo dificil si es posible hacerlo facil? - Why do it the hard way, when you can do it the easy way?
John Waller
Esteemed Contributor

Re: ftp in cron fails, from command works OK

I think the problem might be due to your mput *.tar Try adding a lcd to the directory where your tar files are.

Patrick Wallek
Honored Contributor

Re: ftp in cron fails, from command works OK

You may also need to turn the prompt off. By default mput will prompt y/n for each file.

/usr/bin/ftp -n hulk << EOF

user corp/\ragu test

cd /group/it/sox/midas/

bin
prompt
mput *.tar

bye

EOF
Ragu_5
Occasional Contributor

Re: ftp in cron fails, from command works OK

Thx for all your replies. I am trying each of your suggestions and will keep you posted. Is domainname\username accepted in ftp script? Thx
Ragu
Victor Fridyev
Honored Contributor

Re: ftp in cron fails, from command works OK

Hi,

I think, Jeff is right, the problem is in the environment. I'm afraid that the command a1.sh is not in the PATH, which crontab provides the script. In all cron scripts one must use full path, excluding the commands from /bin and /usr/bin.
Additionally, if you want to use ftp from a script, you can use ~/.netrc file, as follows:

machine ftpserver
login username
password userpasswd
macdef init
bin
get backup.tar.gz
quit


HTH
Entities are not to be multiplied beyond necessity - RTFM
Raghunandhan Srinivasan
Frequent Advisor

Re: ftp in cron fails, from command works OK

Thx, but I have actually not referenced any scipt within this. I will try the .netrc and get back.
Ragu
Raghunandhan Srinivasan
Frequent Advisor

Re: ftp in cron fails, from command works OK

Thx to everyone who responded. I have decided to use rcp to a Sun Solaris box and hopefully I will not have any issues her.
Ragu