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
shell script that would display installing.... when installign something eamani_sun Shell Programming and Scripting 1 05-14-2008 10:51 AM
inconsistent ls command display at the command prompt & running as a cron job rajranibl Linux 5 07-30-2007 05:26 AM
Command Not running in script Dastard Shell Programming and Scripting 2 05-21-2007 02:08 PM
Need to know rhe PID for the Shell Script running pbsrinivas Shell Programming and Scripting 7 01-25-2007 06:10 AM
Shell Script Display? wmosley2 UNIX for Dummies Questions & Answers 2 12-14-2003 11:12 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 09-10-2005
Registered User
 

Join Date: Jul 2005
Posts: 33
PS command does not display shell script running

Quote:
Originally Posted by guhas
i have a script, which is continuously looping. i want to view the script name when i use ps command... it is only showing -sh ...

UID PID PPID C STIME TTY TIME COMMAND
informix 8533 20923 0 18:19:28 pts/ta 0:00 -sh

but i dont have my scriptname displayed .... how can i do that my script is a simple shell script with an infinite loop.


thanx for the cooperation but i want to kill it from outside the script while it is running using the scriptname and i dont see the scriptname
If you execute your script in the background (with &), know that the PID of the last executed background process is saved in $!. Thus do kill $!.

Otherwise, know that whenever you execute a script--an executable file that begins with #!--the operating script automatically converts the command to the form
Code:
interpreter script_name
Thus if you have an executable file called myscript, with contents
Code:
#!/bin/bash
echo "Hello World!"
and you execute it by its name from the command prompt

> ./myscript

rather than passing the script name as an argument to the interpreter

> bash myscript

when the operating system spots that the file is a script--beginning with #!--it converts the command to the form "/bin/bash ./myscript". Some versions of ps--not all of them--will print the process's command name as "interpreter" (here "bash"), rather than as the script name. This is why you are seeing -sh as the command name of the process--does your script start with #!/bin/sh?
To get around this, try format options of ps, with the -o switch. Try ps -o pid,args. This should list your processes with two columns: the first the PID of each process; and the second the complete command with which that process was invoked, which for scripts wil be of the form "interrpeter scriptname". So you should be able to search for the name of your script in the output of ps, like with grep or awk. Try:
Code:
pid=`ps -o pid,args | awk '/script_name/ { print $1 }'`
this will save the PID of the your script in $pid. To kill this process, kill $pid.

Last edited by hadarot; 09-10-2005 at 10:07 AM.
Reply With Quote
Forum Sponsor
  #2  
Old 09-10-2005
Registered User
 

Join Date: Sep 2005
Posts: 4
Thank you
i am not using #!bin/bash
and i am executing withhout ./
I am executing directly by typing scriptname.sh from prompt.
ps -o does not work on my system

how to get the get pid from scriptname?any other ways?
thanks
martin
Reply With Quote
  #3  
Old 09-10-2005
Registered User
 

Join Date: Sep 2005
Posts: 22
sorry

i am also trying to do the same thing and caught in the scriptname.... i am not able to see it

sorry i ll follow the common forum
Reply With Quote
  #4  
Old 09-10-2005
Registered User
 

Join Date: Sep 2005
Posts: 22
Smile thanx

I Got A Lot Info From This Disscussion.
I Created A File The Existing File And Passed The Pid Of The Script Pid.
From A Different Script I Read It And Killed
Reply With Quote
  #5  
Old 09-15-2005
Registered User
 

Join Date: Sep 2005
Posts: 15
if you run your script as
sh <script file>
you can do ps-ef| grep <script file>


alternatively do ps -ef | grep `echo `tty`` this will give you all the processes for the session and selectively kill -ksh sessions
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:46 PM.


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