LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-30-2008, 04:36 AM   #1
YSE
LQ Newbie
 
Registered: Sep 2008
Posts: 2

Rep: Reputation: 0
Execution of a script to be stopped after "x" minutes of time


I have 2 scripts test1.sh and test2.sh which are embedded in main script Test.sh

Test.sh
===============================================
#We are currently in Test.sh
#Some commands
#After executing above commands, we need to execute test1.sh
./test1.sh
./test2.sh
================================================

In the above scenario, I don't want test1.sh to be executed completely, instead, after some "x" minutes, execution of test1.sh should be stopped and script test2.sh should be executed.

Please Note: I am not supposed to change contents of test1.sh.

Please let me know if this is possible.

Thanks a lot.

--YSE

Last edited by YSE; 09-30-2008 at 04:38 AM. Reason: Correction.
 
Old 09-30-2008, 06:19 AM   #2
w3bd3vil
Senior Member
 
Registered: Jun 2006
Location: Hyderabad, India
Distribution: Fedora
Posts: 1,191

Rep: Reputation: 49
Hopefully this should help you out.

Quote:
./test1.sh &
sleep(30)
VAR=`ps x | grep test1.sh | cut -d" " -f1| head -1`
kill -9 $VAR
./test2.sh
So you get the idea..
 
Old 09-30-2008, 11:37 PM   #3
YSE
LQ Newbie
 
Registered: Sep 2008
Posts: 2

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by w3bd3vil View Post
Hopefully this should help you out.



So you get the idea..

Thank you w3bd3vil for the prompt response.

I tried executing the commands and test my script. But test2.sh is getting executed only after test1.sh is completely executed.
 
Old 10-01-2008, 12:00 AM   #4
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 63
No need for all the scripting to get the PID of the backgrounded job. Use $! instead:

Code:
./test1.sh &
PID=$!
sleep 60
kill -TERM $PID
./test2.sh
I don't understand your comment about test2.sh getting executed after test1.sh is completely executed. You indicated in your first post you wanted test2.sh to being after x minutes. That's what the script above does (test2.sh starts 60 seconds after test1.sh started).
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 7 12-19-2015 01:03 AM
X Server broken. start w/ "INIT: ld "x" respawning too fast: disabled for 5 minutes&q tektone Linux - Hardware 5 07-25-2007 07:18 PM
execute a script every 5 minutes "cron" ALInux Linux - General 1 02-10-2006 02:36 AM
Can't install "glibmm" library. "configure" script can't find "sigc++-2.0&q kornerr Linux - General 4 05-10-2005 02:32 PM
INIT: Id "x" respawning too fast: disabled for 5 minutes" Lego3 Linux - Software 0 06-16-2004 08:01 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration