The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
not showing restore information while run script happyv Shell Programming and Scripting 1 11-20-2007 01:05 AM
executing script big123456 Shell Programming and Scripting 1 06-03-2005 04:32 AM
RSH use for executing a script frustrated1 Shell Programming and Scripting 6 10-02-2003 05:24 AM
Executing ksh script from cgi hodges Shell Programming and Scripting 1 05-27-2003 07:57 AM
Executing Ps in script Claude Shell Programming and Scripting 1 11-21-2001 11:01 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 06-13-2005
Registered User
 

Join Date: Feb 2005
Location: London, United Kingdom
Posts: 4
executing script not showing up in ps -efx

Hi everyone, here's my problem. I have a script that runs in a infinite loop, repeating the same action in another script every 10 minutes. We need to monitor whether or not this loop script is running and be able to kill it should the need arise. However, the name of the script does not show up in the ps -efx listing, even though it is clearly running in the other window. Is there a way to make the script show itself in the ps -efx output, or get it's process ID?

Thanks!
Reply With Quote
Forum Sponsor
  #2  
Old 06-13-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,029
if you know the pathname to your script....

fuser /path2yourScript

man fuser
Reply With Quote
  #3  
Old 06-13-2005
Just Ice's Avatar
Lights on, brain off.
 

Join Date: Mar 2005
Location: in front of my computer
Posts: 629
Quote:
Originally Posted by herman404
Is there a way to make the script show itself in the ps -efx output, or get it's process ID?

Thanks!
at the start of the script ... get it to write it's PID into a readable file so you'll always know the PID you need to kill later as required ...

Code:
echo $$ > /tmp/script.PID
Reply With Quote
  #4  
Old 09-10-2005
Registered User
 

Join Date: Sep 2005
Posts: 22
hi

i am facing the same proble came u suggest me how to read it from a file once u read it and send it to a file
Reply With Quote
  #5  
Old 09-10-2005
Registered User
 

Join Date: Jul 2005
Posts: 33
Quote:
Originally Posted by guhas
i am facing the same proble came u suggest me how to read it from a file once u read it and send it to a file
If the filename is as specified above, then
Code:
pid=`cat /tmp/script.PID`
Then use $pid to access the PID. E.g., to kill the process, do kill $pid

But if your system's ps command supports formatted output, with the -o swtich, you can use that instead of saving the PID in a temp file. Try ps -eo pid,args, and search the outpout to see if the name of your script shows up. The importnat thing here is using the args format (as an argument to the -o option). By default, ps outputs the command name as the comm format, which is a shortened form of the command that the system actually executes; the args format gives the full form of the command, which will include the name of the script.

Last edited by hadarot; 09-10-2005 at 10:34 AM.
Reply With Quote
  #6  
Old 09-10-2005
Registered User
 

Join Date: Sep 2005
Posts: 4
thanks ...this willwork
but do we have asolution to this without the write read operation from a file

How do we make ps command display the scriptname that is running ?
wh does it show .sh and not complete scripname.sh.
if the scripname was there we could have found it by simple
ps and grep.
someone in the group suggested the reason for not didplaying scripting name
coud be that #!bash is not inlude in the running script /
any solution that way
Reply With Quote
  #7  
Old 09-11-2005
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,249
I would not suggest building a solution that involves a script running an infinite loop. Why not loop until a "stop" file is found, e.g...
Code:
until [[ -f /tmp/stopfile ]]
do
  :
  sleep 600
done
rm /tmp/stopfile
Instead of killing the script, it can be stopped by using:
Code:
touch /tmp/stopfile
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:14 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0