I am still bit new in shell script area.I am writing down a shell script which I guess somewhere wrong so please kindly correct it. I would be greatful for that.
What I actually want from this shell script is that it will move all the files one by one to another server which can be windows or sun solaris server. Here I have implemented autossh between the two servers.
What actually this shell script must do is first 'file' variable will have the first file name then I try to make a infinite while loop, in which it will cut the third word which come out from the successful ping command. If the value of var is alive then transfer one file to another server, then bring back that file to same server so that they can be compare.If the
output of compare is null then come out of while loop or sleep for 60 second before ping command can be use again.
My intention of making this script is while transfering a file from serverA to serverB if the network broke down for a while say half an hour or so then it will test through the ping command if the ping command say servername is alive then transfer that file again during which network broke down. In this way it will transfer all the files from serverA to serverB
exec < /girish/server # server file will contain only ip address of the other server
for file in `ls -1`
var=`ping $IP | cut -d " " -f3`
if [ $var = "alive" ]
echo "lcd /export/home/user1 \n cd /girish \n mput $file \n bye" | sftp -B 131072 -v $IP 1>sftp1.log 2>sftp2.log
grep -i Uploading sftp1.log >>/girish/output1
grep -i transfer sftp2.log >>/girish/output2
echo "lcd /amit \n cd /girish \n mget $file \n bye" | sftp -B 131072 -v $IP 1>sftp3.log 2>sftp4.log
grep -i Uploading sftp3.log >>/girish/output3
grep -i transfer sftp4.log >>/girish/output4
var1=`cmp /export/home/user1/$file /amit/$file`
if [ -z var1 ]
done ( for closing while loop )
done ( for closing for loop)