This script is just a basic script to download files from a remote machine to local machine using ftp and see whether each file is correctly downloaded or not. cksum command is used to see that local file has same check sum as remote file. If the file is downloaded successfully, it will delete the file remotely.
#!/bin/ksh ### check if already running LOCKFILE="cs_frank_ftp.lock" #lockfile NOFILESTODOWLOAD=64 if [ -f $LOCKFILE ]; then exit fi touch $LOCKFILE # create your lockfile so that any process starting up after _script_dir=`pwd` _download_to_dir="/root/sriram_ftptesting/download" _source_dir="/opt/sriram_testing" _ftp_address="172.18.24.177" _ftp_usr="Varun" _ftp_pwd="root123" [ -f $_script_dir/cksum_remote.lst ] && rm -f $_script_dir/cksum_remote.lst [ -f $_script_dir/cksum_local.lst ] && rm -f $_script_dir/cksum_local.lst cd $_download_to_dir ssh Varun@172.18.24.177 "cd $_source_dir; ls comps.* | while read file ; do cksum \$file ; done" > $_script_dir/cksum_remote.lst 2> /dev/null [ ! -s $_script_dir/cksum_remote.lst ] && echo "No files in the remote location : $_source_dir : Please check,Exiting !!!!" && exit $NOFILESTODOWLOAD for file in `cat $_script_dir/cksum_remote.lst | awk '{print $NF}'` do echo "+++Opening FTP Session to download $file +++" _ftp_exec=`ftp -n -v $_ftp_address << EO_FTP user $_ftp_usr $_ftp_pwd prompt off binary cd $_source_dir get $file bye EO_FTP` cksum $file >> $_script_dir/cksum_local.lst cksum_expected=$(awk -v FILE=$file '$NF==FILE {print $1}' $_script_dir/cksum_remote.lst) cksum_actual=$(awk -v FILE=$file '$NF==FILE {print $1}' $_script_dir/cksum_local.lst) if [ $cksum_expected -eq $cksum_actual ] ; then echo "$file downloaded succesfully with checksum $cksum_actual same as expected: $cksum_expected" echo "removing $file from source : $_source_dir" ssh Varun@172.18.24.177 "rm -f $_source_dir/$file" [ $? -eq 0 ] && echo "$file removed successfully" else echo "$file download not successful" echo "removing localcopy $file and try download once again" fi done rm -f $LOCKFILE exit 0
No comments:
Post a Comment