Results 1 to 5 of 5
Hi,
I have a shell script to identify whether the process is running or not. If the process is not running, then I execute another script file to run my ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 11-09-2010 #1Just Joined!
- Join Date
- Jul 2009
- Posts
- 6
Displaying process id in my shell script but there is no such process
Hi,
I have a shell script to identify whether the process is running or not. If the process is not running, then I execute another script file to run my application. Below is my script and saved this script as monitorprocess.sh
When I execute the script file as "sh monitorprocess.sh". I got printed with process id, something like 4726 4727. But, if I execute this ps -ef | grep -v grep | grep "applicationname.sh" | awk '{print $2}' in the shell. I got no output.Code:#!/bin/bash result=$(ps -ef | grep -v grep | grep "applicationname.sh" | awk '{print $2}') echo $result if [ "$result" == "" ]; then echo "process is not running" sh applicationname.sh fi
Actually, executing shell script should not print the process id, because the actual process is not running. Please, help me to fix it.
ThanksLast edited by vishnukumar; 11-09-2010 at 10:43 AM. Reason: Improvement in the heading
- 11-09-2010 #2
I would do it like this:
Code:#!/bin/bash # appname="whatever.sh" result=$(pidof $appname) if [ $result ] then echo "Process $appname running with PID $result" else echo "Launching application $appname" sh $appname fi exit 0
- 11-09-2010 #3Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 10,160
If the process may be a shell script, you need to add the '-x' option to pidof. That will get the pid of processes and/or scripts.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 11-12-2010 #4Just Joined!
- Join Date
- Jul 2009
- Posts
- 6
Hi,
I have fixed the issue with the script. The fix is, I have added the correct path to the shell script within another shell script. Below is my script
Code:#!/bin/bash result=$(ps -ef | grep -v grep | grep "reportgen.sh" | awk '{print $2}') if [ "$result" == "" ]; then sh /var/www/Reportgen/reportgen.sh $1 $2 $3 $4 $5 $6 $7 fi
- 11-12-2010 #5Just Joined!
- Join Date
- Jul 2009
- Posts
- 6
Barriehie, Rubberman,
I have tried with "pidof $appname" or "pidof -x $appname", however when the process is running, this script doesn't print any result. I also pasted this "pidof applicationname.sh" in the terminal and there is no output. I don't know how to use pidof?
QUOTE=Rubberman;814525]If the process may be a shell script, you need to add the '-x' option to pidof. That will get the pid of processes and/or scripts.[/QUOTE]


Reply With Quote
