Right now I have implemented autossh between ServerA & ServerB which are sun solaris based. I have made this shell script. 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 means 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 and control should back to new statements of shell script (means statement after sftp statement). Could any body tell me how to use trap command so that my shell script won't get hang.
I am bit new to Shell scripting and I don't no how to incorporate trap command in this shell script
Last edited by vino; 03-12-2008 at 05:49 AM..
Reason: code tags
basename=${0##*/}
trap 'print "$basename: Unexpected rc $? at line $LINENO"; exit 1' ERR # exits script for any non-zero return-code
trap '
#
# command to clean up on any script exit, any rc value
#
' EXIT
I am not sure if I understood this correctly: You want to initialize SFTP transfer and detect when it fails or is running more than 5-10 minutes?
If so, then you could use multiple threads where one is watching the other one, or you could just wait until the SFTP session finishes.
Example code (I give no guarantee that it will work):
#!/bin/ksh
sftp -b batch_script login@server &
sleep 600
if [[ -n $(jobs) ]] ;then
typeset mypsid=$(jobs -l|awk '{print $3}')
if [[ -n "$mypsid" ]] && [[ "$mypsid" == [0-9]+ ]] ;then
kill -9 $mypsid
fi
repeat_sftp_sending
fi
Example:
I have server name A with an IP : 125.252.235.455
I have an username /password to login into this server under SSH connection
In this server i have a path /apps/user/filename(Big.txt)
Everyday we used to get the filename as Big.txt.
I want a shell script to monitor this path... (4 Replies)
sqlplus -s usrname/password@dbSID <<-SQL >> logfile
@create_table.sql
commit;
quit;
SQL
I am running this script to execute an sql file.
I want to display the oracle error if anything found during execution of the sql file and exit from script.
Please suggest How do it. (1 Reply)
I'm learning about the trap command from my bash book. I tried out the little script they gave:
trap "echo 'You hit control-C!' " INT
while true; do
sleep 60
done
But when I type control-c, the script just stops and the message is not displayed. I checked stty all and saw that control-c... (11 Replies)
Hi ,
i have a scenario where...i have to put a check where if script is executing more than 15mins i have to kill that script and n retry again 2nd time.
i this case i can use background process to do it but i feel trap will be the efficent way to do so...
but i dont know much about it... (1 Reply)
I know there is a command called trap which can be used to capture the signals from a shell script and redirect the control to a required function (such as a cleanup).
My question is - Those of you who have written lot of shell scripts - do you always write a set of trap commands to capture... (4 Replies)
Hi All,
i have an issue regarding trap command.
i have specified trap function in the beginning of the script to catch some signals but in the later part of the script i want to remove the effect of this.
Can anybody help me out of this.
for e.g. pressing Ctrl+C for the first time should... (2 Replies)
how to trap the ctrl c in unix shell script
my script is running in while loop it should not be terminate with ctrl c.
if i press ctrl c while running script it shloud ignore the same.
please healp..........
thanks in advance (2 Replies)
Hi folks,
I have tried to add some trap detection in the below script....this script is used to monitor database activities...in a rather awkward way :rolleyes:....
The idea behind adding trap is that....this script creates lots of temporary files in the running folder to store the count... (1 Reply)
Hi,
I would like to know the use of TRAP command. I am very new to the UNIX environment. I have just started learning the basic. So please teach me in a very simple way to understand.
Also i would like to know the use of following command:
trap 'dialog --msgbox "Script Aborted1" 6 50 ;... (2 Replies)