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

FTP'ing from a Unix Script

Status
Not open for further replies.

mjm22

Programmer
Nov 11, 2003
10
GB
I wish to run some ftp commands from a shell script. I thought that this would be easily done with the following...

++++++++

ftp -inv $IP <<-ENDFTP >$DIALOG
user $USER $PASSWORD
cd /home/user1/log
bin
put $REF_FILE $TO_REF_FILE
bye
ENDFTP

status=`grep -c &quot;Not connected&quot; $DIALOG`
if [ $status != &quot;0&quot; ]
then
echo &quot;ERROR - Connection to distribution system is down, $IP&quot;
exit 4
fi

----------

The ftp works fine and the appropriate messages get sent to the $DIALOG file. However the rest of the shell script seems to be ignored. The line starting status= never gets run.

I have also tried without redirection to the $DIALOG file as follows, again the following echo command does nbot get run.

+++++++

ftp -inv $IP <<-ENDFTP
user $USER $PASSWORD
cd /home/user1/log
bin
put $REF_FILE $TO_REF_FILE
bye
ENDFTP

echo &quot;Here I am&quot;

-------

Shell is ksh and all of the variables are ok ( thus the ftp actually working fine).

Any suggestions as to why the rest of the script is not executing?

Cheers

Mike
 
Have you tried this ?
Code:
echo &quot;user $USER $PASSWORD
cd /home/user1/log
bin
put $REF_FILE $TO_REF_FILE
bye&quot; | ftp -inv $IP >$DIALOG
echo &quot;Here I am&quot;

Hope This Help
PH.
 

Thanks, that works fine. Not quite sure why the first method didn't work though.

Cheers anyway.

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top