Hi, I'm trying to make a little script to see if a process is running or not, the problem is...it always says it's running.
It's probably fault of the script itself, because ps -ef lists the arguments I send to the script
if ps -ef | grep -q $process
then
echo " process is running"
That's how I find if a process is running. I always get "pocess is running" no matter how stupid I make up the name of the process. It's always shown twice, one in /bin/bash and the other in grep.
Any tips?
edit: Also, I'd gladly accept a nice bash scripting tutorial that starts from scratch if anyone knows a good one.
In this case, since the actual process name is hidden in a variable, I'd go with adding a second pipe to your statement like so:
The -v option tells grep to ignore results, therefore you're telling it to ignore "grep" processes.
Or ... you could do this (ksh - don't know what shell you've got) :
This accounts for the fact that you'll always get the "grep" process. But if you ever don't get it for whatever reason, you'll get a false miss. I don't like relying on this.
I've seen some folks when displaying actual process names and not putting the name in a variable do this:
The bracket expression somehow precludes the grep process from showing up in the reults. As I say "somehow" means I don't understand why it works, and until I do, I don't trust it. ;-)
Uhh...Just noticed, doesn't work with bash (my bad, I forgot mentioning that I was working with bash).
It just stores '[f]oobar' in that variable and doesn't find anything that is running.
Edit: Thanks rwuerth! I added one more pipe and got it done (actually I added 2 more pipes since I needed to remove also the name of the script executing or else it'll also show the argument given, which leads to failure since the argument would be recognised as a process running).
Last edited by lamachejo; 12-08-2010 at 06:29 PM..
The bracket expression somehow precludes the grep process from showing up in the reults. As I say "somehow" means I don't understand why it works, and until I do, I don't trust it. ;-)
Bracket notation denotes a list of single characters to match.
For example "grep [cfh]at" would match:
so "grep [b]ind" matches
but not
.
This User Gave Thanks to Chubler_XL For This Post:
Hi all,
As i am new to shell script.Please help me to write a Shell script to find out process name that are running for last 10 days.
Thank's in advance. (8 Replies)
I have to kill the process "test" for a maintenance I do but want the script to check when it comes back up.
I can get what I want when I run this while loop:
while true;do ps -ef | grep test | grep -v grep | sed -e 's/^*//';sleep 60;done
but I want the script to do it for me and as soon as... (6 Replies)
Hello,
I have multiple scripts (vlc1, vlc2,...vlc5) and as I do not know how to run them as upstart processes, I entered my script links into rc.local file.
Here is the sample one for process vlc1:
$ nano /etc/rc.local
added below line into rc.local
/var/bin/./vlc1 &
Port nr of vlc1... (7 Replies)
Hi, i was looking for an answer for some trouble im having runing a script in the cron, thing is, that when i run it manually it works just fine. But when cron runs it, it just doenst work. I saw a reply on a similar subject, suggesting that the . .profile worked for you, but im kind of... (9 Replies)
#!/bin/sh
CHECK='ps aux | grep start.jar | grep -v grep | wc -l'
if
then
/usr/local/jre-1.7.0/bin/java - jar start.jar &
else
fi
Could anybody advise whats up with this code im trying to put this in as a cron job to check that solr search engine is running every 10secs and if... (10 Replies)
Hi,
Can anyone please tell me how to write a shell script to check
whether a process if running or not.... if its still running then wait for sometime and if not then run the next query.
Also, Under my one main script main.sh I have to run 2 scripts simutaneously which take some time to... (2 Replies)
I'm new to expecting and i want to create a script to ssh to a device,check is a process is running and display that the process is running or not.This is what i have so far
After executing this script i get an error.
#!/usr/bin/expect
set timeout -1
set ip "machine ip goes here"
set... (5 Replies)
Hello all,
I would be happy if any one could help me with a shell script that would determine all the processes running on a Unix server and post a mail if any of the process is not running or aborted.
Thanks in advance
Regards,
pradeep kulkarni.
:mad: (13 Replies)
How do I make a shell script to see if a certain process is running.
The process shows up on ps aux as /usr/sbin/daemon
eg:
if
/usr/sbin/daemon
else
#nothin
basically i want to run the process if it isnt running/ has been stopped.
Thanks. (2 Replies)
Hai Friends,
I have to develop a script that checks for a particular process say x.exe once every day and report if its not running say through a blat mail.
I need this to run in a given list of pc from a single point.
Any suggestion of how to go abt this
Thnx for any help (1 Reply)