how to stop execution of a script after one hour


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to stop execution of a script after one hour
# 1  
Old 11-19-2010
Question how to stop execution of a script after one hour

I have a shell script that writes some data in a file. I want to stop the script after one hour from start of execution using "EXIT 1".
how to do it. I don't want to use CRONTAB.
# 2  
Old 11-19-2010
Would be easier if you'd post what you have in your script
# 3  
Old 11-19-2010
Should work with ksh,bash:
Code:
my_pid=$$
trap "exit 1" USR1
( sleep 3600; kill -USR1 $my_pid ) &

# time consuming stuff here

# 4  
Old 11-19-2010
I have the same query. please find my script below..

Code:
find . -type f +mmin +5 > /tmp/test_file

while read FNAME
do
scp -i /root/.ssh/id_dsa_noauth $FNAME myserver.com:/tmp/

done < /tmp/test_file

if there some 1000 files in the folder, the script pushes the files one by one and sometimes goes into a hang state after 1 hour. so is there a way to exit the script after 1 hour....
p.s the above script is just the core part of a big script which is designed for special purposes...
# 5  
Old 11-19-2010
@Tuxidow: That could be optimized:
Code:
find . -type f +mmin +5 -print | xargs -I{} -n 100 scp -i /root/.ssh/id_dsa_noauth {} myserver.com:/tmp/

See man xargs
# 6  
Old 11-19-2010
I can't run the script as u suggested...

it should go in a loop...after successful copying each file should be moved to a "processed" directory and also log the status of the file move in a report.

is there any other way?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Stop script execution, when we encounter error

Team, Im new to shell scripting please help in below issue: Considering scenario i have 1.sql,2.sql,3.sql and 4.sql . If my second script fails my loop should come out and should not execute 3.sql and 4.sql. Here is my code. #! /bin/bash echo "exit" | user/password | grep Connected >... (4 Replies)
Discussion started by: preethi87
4 Replies

2. Shell Programming and Scripting

Shell script to be run every one hour

How can we run shell script every one hour. Anyone having code unit for this? (1 Reply)
Discussion started by: Pratiksha Mehra
1 Replies

3. Shell Programming and Scripting

How to run a process continuously for an hour then stop?

Hi I have a shell script I would like to run it has to run twice a day every 5 seconds for an hour I can do this with cron but I was hoping there was an easier way. Is there a way to make a process sleep only at a certain time of day say between 1 and 2 pm? Or under certain conditions? Any help... (8 Replies)
Discussion started by: Paul Walker
8 Replies

4. Shell Programming and Scripting

To stop execution in cron

hi guys i have a question my cron should start executing minute but it sould stop execute only i have tried tis 10 * * * * /home/sample.sh >> /data/band/cron_$(date+|%Y|m|d).log (2 Replies)
Discussion started by: azherkn3
2 Replies

5. Shell Programming and Scripting

Need a script to see top processes for every hour

Hi All, I am new to Scripting , please give me guidance to write the script to see top processes on the Linux operating system. I executed this script on my Virtual Server(Linux) DATE=`date +%Y%m%d%H%M%S` HOME=/home/xmp/testing/xmp_report RADIUS_PID=`xms -xmp sh pr | grep... (2 Replies)
Discussion started by: madala
2 Replies

6. Shell Programming and Scripting

How to convert 24 hour time to 12 hour timing?

Hi friends, I want to convert 24 hour timing to 12 hour please help me... my data file looks like this.. 13-Nov-2011 13:27:36 15.32044 72.68502 13-Nov-2011 12:08:31 15.31291 72.69807 16-Nov-2011 01:16:54 15.30844 72.74028 15-Nov-2011 20:09:25 15.35096 ... (13 Replies)
Discussion started by: nex_asp
13 Replies

7. Shell Programming and Scripting

how to loop script for every 1 hour

Hi All, Need to run a1.sh script using nohup command (since crontab facility not there in my unix server) as below: nohup ksh -x a1.sh & a1.sh contains: nohup ksh -x b1.sh 2> b1.log & In a1.sh script i need to trigger b1.sh script every one hour. How to loop b1.sh to run for every 1... (4 Replies)
Discussion started by: HemaV
4 Replies

8. Shell Programming and Scripting

Stop execution of script if some condition fails

After my if condtion give rusult true then script should stop execution. Please advice...Thnaks in advance (1 Reply)
Discussion started by: vivek1489
1 Replies

9. AIX

stop execution of script with in the script

Hello i want to incorporate of piece of code in the shell script which checks whether same script is already running or not. If it is already running i want to come out (exit) if its not then continue with the execution of the script. Any help would be very much appreciated Thanks (3 Replies)
Discussion started by: dsdev_123
3 Replies

10. Programming

how to stop execution in for loop

Hi all, I am working on a c source code nearly 2000 line . it contains one big for( i=0; i< 200 ; i++ ) loop of around 600 lines could any tell me how to break the execution of prog when the value of i is 50 in for loop so that i can check inside the loop. Thanks.. (1 Reply)
Discussion started by: useless79
1 Replies
Login or Register to Ask a Question