![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 05:10 AM |
| Shell Script Display? | wmosley2 | UNIX for Dummies Questions & Answers | 2 | 12-14-2003 10:12 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
PS command does not display shell script running
Quote:
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 Code:
#!/bin/bash echo "Hello World!" > ./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 }'`
Last edited by hadarot; 09-10-2005 at 10:07 AM. |
| Forum Sponsor | ||
|
|
|
|||
|
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 |
|
|||
|
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 |
|||
| Google The UNIX and Linux Forums |
| Thread Tools | |
| Display Modes | |
|
|