| | |
correct my syntax in shell script
![]() |
•
•
Join Date: Feb 2008
Posts: 2
Reputation:
Solved Threads: 0
Dear all
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
#! /bin/sh
exec < /girish/server # server file will contain only ip address of the other server
read IP
for file in `ls -1`
do
while true
do
var=`ping $IP | cut -d " " -f3`
if [ $var = "alive" ]
then
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 ]
then
break
else
sleep 60
fi
else
sleep 60
fi
done ( for closing while loop )
done ( for closing for loop)
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
#! /bin/sh
exec < /girish/server # server file will contain only ip address of the other server
read IP
for file in `ls -1`
do
while true
do
var=`ping $IP | cut -d " " -f3`
if [ $var = "alive" ]
then
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 ]
then
break
else
sleep 60
fi
else
sleep 60
fi
done ( for closing while loop )
done ( for closing for loop)
•
•
Join Date: Feb 2008
Posts: 2
Reputation:
Solved Threads: 0
#! /bin/sh
exec < /girish/server # server file will contain only ip address of the other server
read IP
cd /anshu
for file in `ls -1rt`
do
while true
do
var=`ping $IP | cut -d " " -f3`
if [ $var = "alive" ]
then
echo $var
echo "lcd /anshu \n cd /gir \n mput $file \n bye" | sftp -B 131072 -v $IP 1>/girish/sftp1.log 2>/girish/sftp2.log
grep -i Uploading /girish/sftp1.log >/girish/output1
grep -i transfer /girish/sftp2.log >/girish/output2
echo "lcd /amit \n cd /gir \n mget $file \n bye" | sftp -B 131072 -v $IP 1>/girish/sftp3.log 2>/girish/sftp4.log
grep -i Uploading /girish/sftp3.log >/girish/output3
grep -i transfer /girish/sftp4.log >/girish/output4
var1=`cmp /anshu/$file /amit/$file`
echo $var1
var2=`cmp /girish/f2 /girish/f3` # value in f2 and f3 are identical which is a
echo $var2
if [ $var1 = $var2 ]
then
break
fi
else
sleep 60
fi
done
done
Now I correct this script which is working fine. But still I am facing one problem which I am going to discuss now.
The problem is when I sftp some files (suppose there is 10 files I have to transfer through sftp) from one server
to another. During sftp if suppose network goes down then the process get hang and it does not transfer further files.
But if network goes down during comparing the files then only that file didnot get transfer and it will sftp other 9 files.
One strange thing also find that if suppose during transfer of files network goes down, if the network goes up within
5 min of goes down then it will sftp all the files. But if network goes up after five minutes say 10 min. then either
process get hang or sftp all the files execpt one during which network goes down.
I guess, I have to use trap command if the network goes down during transfer of files through sftp command. so that my
shell program should not hang. Could any body tell me how to use trap command so that my shell script won't get hang
exec < /girish/server # server file will contain only ip address of the other server
read IP
cd /anshu
for file in `ls -1rt`
do
while true
do
var=`ping $IP | cut -d " " -f3`
if [ $var = "alive" ]
then
echo $var
echo "lcd /anshu \n cd /gir \n mput $file \n bye" | sftp -B 131072 -v $IP 1>/girish/sftp1.log 2>/girish/sftp2.log
grep -i Uploading /girish/sftp1.log >/girish/output1
grep -i transfer /girish/sftp2.log >/girish/output2
echo "lcd /amit \n cd /gir \n mget $file \n bye" | sftp -B 131072 -v $IP 1>/girish/sftp3.log 2>/girish/sftp4.log
grep -i Uploading /girish/sftp3.log >/girish/output3
grep -i transfer /girish/sftp4.log >/girish/output4
var1=`cmp /anshu/$file /amit/$file`
echo $var1
var2=`cmp /girish/f2 /girish/f3` # value in f2 and f3 are identical which is a
echo $var2
if [ $var1 = $var2 ]
then
break
fi
else
sleep 60
fi
done
done
Now I correct this script which is working fine. But still I am facing one problem which I am going to discuss now.
The problem is when I sftp some files (suppose there is 10 files I have to transfer through sftp) from one server
to another. During sftp if suppose network goes down then the process get hang and it does not transfer further files.
But if network goes down during comparing the files then only that file didnot get transfer and it will sftp other 9 files.
One strange thing also find that if suppose during transfer of files network goes down, if the network goes up within
5 min of goes down then it will sftp all the files. But if network goes up after five minutes say 10 min. then either
process get hang or sftp all the files execpt one during which network goes down.
I guess, I have to use trap command if the network goes down during transfer of files through sftp command. so that my
shell program should not hang. Could any body tell me how to use trap command so that my shell script won't get hang
•
•
•
•
Dear all
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
#! /bin/sh
exec < /girish/server # server file will contain only ip address of the other server
read IP
for file in `ls -1`
do
while true
do
var=`ping $IP | cut -d " " -f3`
if [ $var = "alive" ]
then
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 ]
then
break
else
sleep 60
fi
else
sleep 60
fi
done ( for closing while loop )
done ( for closing for loop)
![]() |
Similar Threads
- script not working in RedHat Linux. (Shell Scripting)
- need help with a project (Shell Scripting)
- Virus Of Death - Help Needed! (Viruses, Spyware and other Nasties)
- Apache rewrite map (PHP)
- writing a script (Shell Scripting)
Other Threads in the Shell Scripting Forum
- Previous Thread: Bash Procedure
- Next Thread: reboot a system!
Views: 3938 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for Shell Scripting





