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

Hi, I've a C Shell Script runni 1

Status
Not open for further replies.

nithin97

Programmer
Oct 23, 2002
25
US
Hi,
I've a C Shell Script running every 15 minutes which opens a ftp session and downloads files from remote site. But sometimes the ftp session hangs up due to network delay or anyother reason and the session remains open. But after 15 minutes another ftp session opens according to my script. But the thing is I want to close the previous session which hung up before the next session starts. So what should be added to the script to check if any previous session is still open and kill it ?
Thanks much.. Your answers are really apprciated...
 
Code:
#!/bin/sh

while [ 1 ] ; do
    <ftp gubbins>
    sleep 900 # 15 mins
done

then you won't need to worry about it.

ps, if it's an ftp download problem, have you looked at wget?
 
Hi,
have your script record its PID in a file and then check it when the script starts up again. On the other hand maybe it isn't HUNG maybe the transfer is just taking a long time.

if ( -f cat /tmp/myftppid ) then
set oldpid = `cat /tmp/myftppid`
ps -p $oldpid | egrep &quot;myftpscript&quot; ; set stat = $status
while ( $stat == 0 )
# Last invocation of the script still running....
@ x ++
if ( $x == 10 ) then
# tried 10 times to kill it and it wouldn't die
echo &quot;Couldn't kill old process&quot;
echo &quot; &quot;
exit 5
endif
echo &quot;Old FTP still running &quot;
kill -9 $oldpid
sleep 1
ps -p $oldpid | egrep &quot;myftpscript&quot; ; set stat = $status
end
endif

# put the PID in a file so we can check it next time we start
echo $$ >! /tmp/myftppid

# rest of the script

.
.
.

# remove the PID file if the script complete correctly.

rm -f /tmp/myftppid
 
Hi TDATGOD,

Thanks for your awesome reply... Actually I'm new to Unix Shell Scripting.. Can you please clarify me some doubts in ur script.... Sorry if I am disturbing you again..

Doubt 1 :
the following line gives syntax error saying
Error message : if: Expression syntax
Error line : if ( -f cat /tmp/myftppid )

Doubt 2 :
what does this following line do ?
| egrep &quot;myftpscript&quot;

and what does this following loop do ?
@ x ++
if ( $x == 10 ) then
# tried 10 times to kill it and it wouldn't die
echo &quot;Couldn't kill old process&quot;
echo &quot; &quot;
exit 5

Thank you very much....




 
Sorry I posted my response int he other thread.

thread822-388360

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top