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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FTP in a shell script

Status
Not open for further replies.
Oct 9, 2003
174
0
0
US
I am attempting to ftp transfer an oracle export file between two solaris servers. The script will run fine if called manually logged in under the oracle account but when put into the oracle crontab to run it has some problems. I can't seem to get the script to run from the cron. Can anyone shed some light on this?

HERE IS THE SCRIPT *********************************

#!/bin/sh
HOST='bugsy.domainame.com'
USER='oracle'
PASSWD='xxxxxxxx'
FILE='*.dmp.Z'
L_FOLDER1='/u06/exports/deltekcp'
#L_FOLDER2=
D_FOLDER='/u02/enterprise_exports'
#
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
lcd $L_FOLDER1
cd $D_FOLDER
bin
put $FILE
quit
END_SCRIPT
exit 0




HERE IS THE CRON ENTRY *********************************
#
#
30 01 * * * /morgan/bin/ftp_exports.scr > /morgan/working/ftp.out 2>&1
#


Thanks in advance
 
Hi. Try including the PATH variable it would use if run interactively early within the script, as cron runs in a(very) restricted environment of it's own.
 
Just add a variable named PATH like this to my script?

PATH=/opt/SUNWns6:/usr/bin:/usr/ucb:/usr/sbin:/etc:/u01/app/oracle/product/8.1.7/bin:/usr/dt/bin:/usr/local/bin

Do I have to do an export of it like this?

export $PATH

FULL SCRIPT *********************************

PATH=/opt/SUNWns6:/usr/bin:/usr/ucb:/usr/sbin:/etc:/u01/app/oracle/product/8.1.7/bin:/usr/dt/bin:/usr/local/bin
export $PATH
#
#!/bin/sh
HOST='bugsy.domainame.com'
USER='oracle'
PASSWD='xxxxxxxx'
FILE='*.dmp.Z'
L_FOLDER1='/u06/exports/deltekcp'
#L_FOLDER2=
D_FOLDER='/u02/enterprise_exports'
#
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
lcd $L_FOLDER1
cd $D_FOLDER
bin
put $FILE
quit
END_SCRIPT
exit 0


Thanks again
 
Sure, or just put export before your PATH=etc to define and export it at the same time. Can you test it?

 
OK, I added the Path statment as described to the script. Directly after the shell declaration. When I call the script manually now all I get is:

#./ftp_exports.scr > /morgan/ftp.out
./ftp_exports.scr: PATH=/opt/SUNWns6:/usr/bin:/usr/ucb:/usr/sbin:/etc:/u01/app/oracle/product/8.1.7/bin:/usr/dt/bin:/usr/local/bin:
#


It just returns me back to the prompt without ftp'ing any files. Below is the current version of the script.

#!/bin/sh
#
export PATH=/opt/SUNWns6:/usr/bin:/usr/ucb:/usr/sbin:/etc:/u01/app/oracle/product/8.1.7/bin:/usr/dt/bin:/usr/local/bin
#
HOST='xxxx.xxxx.com'
USER='oracle'
PASSWD='xxxxxxxx'
FILE='*.dmp.Z'
L_FOLDER1='/u06/exports/deltekcp'
#L_FOLDER2=
D_FOLDER='/u02/enterprise_exports'
#
ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
lcd $L_FOLDER1
cd $D_FOLDER
bin
put $FILE
quit
END_SCRIPT
exit 0



 
Sorry, I meant put the export like this:

export PATH=/opt/SUNWns6:/usr/bin:/usr/ucb:...etc

rather than have export on a line of it's own. I'm finding the cutting and pasting on the site a little unpredictable these days, is anyone else?

I notice you have put $FILE in your script, but FILE is defined as '*.dmp.Z'. Is this correct and does it work interactively for a number of files?
 
Sorry about that Ken, it must have been a copy\paste error on my post as well. The export and Path are in the same line seperated by a space.

Also the *dmp.Z" works when I kick the script off manually.

Thanks for your help on this.
 
Ken, I don't think the export and definition on one line works with the Bourne shell ([tt]/bin/sh[/tt]). That's Korn shell or BASH, I believe. That will have to be...
Code:
PATH=/opt/SUNWns6:/usr/bin:/usr/ucb:...etc
export PATH

Hope this helps.
 
whon´t this work aswell:

PATH=$PATH:/new/path
export PATH
 
Thanks fellas, adding the PATH statement on a seperate line as the export PATH statement worked. One last question for you guys, this will probably be something quick as you guys seem to know what your doing out there in the scripting world.

I'm trying to enhace the script and do a check of the export log file to see if it completed correctly before ftp'ing it over. I setup a sample script to test some functionality but Im getting an error on a simple string test. Is my syntax correct? See below, thanks again.

SCRIPT ****************************
#!/bin/ksh
###################################################################
DELTEKCP_EXP_DIR='/u06/exports/deltekcp'
DELTEKCP_LAST_LOG_FILE=`ls -t $DELTEKCP_EXP_DIR/deltekcp_oraexp*.log | head -1`
DELTEKCP_EXP_STATUS=`tail -1 $DELTEKCP_LAST_LOG_FILE`
TEST="Export terminated successfully without warnings."
#
echo $DELTEKCP_EXP_STATUS
if [ $DELTEKCP_EXP_STATUS = $TEST ]; then
echo "GOOD"
else
echo "BAD"
fi

END SCRIPT **********************************

OUTPUT **************************************

Export terminated successfully without warnings.

./tt2[9]: terminated: unknown test operator
BAD

 
Try if [ ${DELTEKCP_EXP_STATUS} = ${TEST} ]; then

rather than your version (note the curly brackets).
 
Sorry Ken,

Same "unknown test operator" error message reiceved when using the {}



 
OK, I got it now. I had to put the variables in quotes like this:
...
...
if [ "$DELTEKCP_EXP_STATUS" = "$TEST" ]; then
...
...
 
Yep, that's what I meant of course (believe that and you'll believe anything ;-) ). I was forgetting this was sh again! Must keep taking the tablets.....

Well done.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top