SunQuest
           UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now!
  #1  
Old October 28th, 2004, 04:41 AM
vinoth.ilango vinoth.ilango is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 2 vinoth.ilango User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile Bash scripting

can anyone help on the following problem.


System Configuration : SunOS sun210 5.9
-----------------------------------------


I have two scripts "Master and Restart" script.

- From the master script , I have to start, stop the restart script on certain conditions.

- To achieve the above functionality, I need to get the processID of the restart script. But when i try the following script I am not able to get the processId.

Sample Master Script
====================

./restart.sh &

while true; do
if [ check for some condition ]
then
restartId=`ps -ef | grep "restart.sh" | grep -v "grep" | sed /zap/d | cut -c10-15`
if [ -n "$restartId" ]
then
echo "Killing the restart script"
kill -9 $restartId
fi
fi
sleep 1
done



- When I manually tried to '$ Ps -ef | grep restart.sh' , I could not see any process running.

Is there any better and efficient way to do the above.

Thanks and Regards,

Vinoth

vinoth.ilango@gmail.com

Reply With Quote
  #2  
Old October 28th, 2004, 09:49 AM
andyb1ack andyb1ack is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 60 andyb1ack User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 14 sec
Reputation Power: 4
hi,

i've had to do something similar in the past a few times.

i ended up getting the script that was being checked for to echo it's process id ($$) to a log file, and the master script then read that process id from the file...

feels like a bodge, but it worked a treat

Reply With Quote
  #3  
Old October 29th, 2004, 12:53 AM
guggach guggach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jul 2004
Location: Middle Europa
Posts: 1,083 guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level)guggach User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 Days 19 h 44 m 45 sec
Reputation Power: 9
if i understand your probl, you need a prog
- starting something if not still running
- stopping something if running
- restart (this is stopp+start) something
do it!
1) it's running ?
2) yes: exit, no: start!
3) required restart? kill it and restart this script

btw: forget this stupidity
restartId=`ps -ef | grep "restart.sh" | grep -v "grep" | sed /zap/d | cut -c10-15`
i see you use SVR4 ps
read man pages
ps -efocomm|sed "s?.*$0 ??"
check the output
(at the moment i am not on *nix,
change comm by args if not matching)

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Bash scripting


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway