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

ftp Shell Script

ftp scripts

ftp Shell Script

by  bjverzal  Posted    (Edited  )
#!/bin/ksh
bindir="/home/ftp/bin"
logdir="/home/ftp/log"
ftp="/usr/bin/ftp"
Email="[Some E-mail Address]"
IP="10.124.33.29"
user="[user-id]"
pass="[password]"
ifile="[source file]"
ofile="[destination file]"
type="asc"
myname=`basename $0`
verbose="verbose"
dd=`date +%d`
log="$logdir/$myname.$dd.log"
host=`hostname`
rc=0
boj=`date`

exec 1>$log 2>&1

echo "\n##### Begin FTP Parameters #####\n"
echo "Program Name: $myname"
echo "Process ID: $$"
echo "Log file name: $log"
echo "Email: $Email"
echo "Source Machine $host"
echo "Destination Machine: $IP"
echo "User ID: $user"
echo "Password: ##############"
echo "Source File: $ifile"
echo "Destination File: $ofile"
echo "\n##### End FTP Parameters #####\n\n"

echo "##### Begin FTP Session #####\n"

echo "open $IP
user $user $pass
$verbose
$type
put $ifile $ofile
close
quit" |$ftp -n

echo "\n##### End FTP Session #####"

foo=`grep -i "cannot" $log`
if [ "$?" -eq "0" ] ; then
rc=1
status="Destination file does not exist\n"
fi
foo=`grep -i "does not" $log`
if [ "$?" -eq "0" ] ; then
rc=1
status="${status}Source file does not exist\n"
fi
foo=`grep -i "killed" $log`
if [ "$?" -eq "0" ] ; then
rc=1
status="${status}File transfer process has abended\n"
fi
foo=`grep -i "space" $log`
if [ "$?" -eq "0" ] ; then
rc=1
status="${status}Ran out of disk space before completion of copy\n"
fi

if [ "$rc" -eq "0" ] ; then
status="Successful"
fi

eoj=`date`
echo "\nJob start time: $boj"
echo "Job end time: $eoj"
echo "\nResult code: $rc ($status)"

mail -s "FTP results from $myname" $Email <$log
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top