Need a script to check the number of process running on Linu

Unxis, inc Sco group - virtual disk mana...
March 11, 2015 at 13:04:50
Specs: Linux, 8 Gig
Hi All,

I am looking for a script for the Linux server which can give me the number of process running on that.

for ex:
Process A = 1
Process B = 1
Process C = 2
Process D = 1


See More: Need a script to check the number of process running on Linu

Report •

#1
March 11, 2015 at 13:21:33
Your question is not clear. Every process consists of just one running process.

Report •

#2
March 11, 2015 at 13:51:04
we are getting some issue where multiple process gets started itself and causing the issue.

thsts why I need help to coount the number of process running...

if its only process then its ok or if there are more then one then its an issue.


Report •

#3
March 11, 2015 at 14:57:50
It sounds as if you need to use a mutex to prevent multiple instances of the program running: http://www.experts-exchange.com/Dat...

Report •

Related Solutions

#4
March 17, 2015 at 08:13:44
Hi All,

I have created my script as I was looking for.....

My script is running on daily basis and sending me the output in mail.

Now I want to modify script in below manner.

I will set its crontab to run after every 1 hour however it should send me mail if there is any error or if there is more then one process running for a monitored service.

Please let me know how can I set that up..

regards,


Report •

#5
March 17, 2015 at 21:28:16
This link describes how to setup cron:

http://www.computing.net/answers/un...

As the link above mentions, make sure you include your PATH variable and other enviromental variables.

The below example runs yourscript.sh at the top of each hour:

0 * * * * yourscript.sh 2> errorfile.txt > youroutput


Report •

#6
March 18, 2015 at 07:22:43
Hi Nails,

I know how to setup the crons.....

Need to modify my script and it should send me mail if there is any error or if there is more then one process running for a monitored service
.


Report •

#7
March 18, 2015 at 11:54:04
Hi,

Please find the below script which I have created to check the services and Process.

This script is checking the status of services and number of instances running for the corresponding process.
It already scheduled to check the status on daily basis and sending the output as a mail.

What I need..?
Now I don’t want it to send me mail daily.
If any service is not running/ stopped in state or any process’s instance is more than 1 or less than 1, then I need it to send me a mail.

******************************************************************************
#!/bin/ksh

# Get date
DATE=$(/bin/date +%Y%m%d)
HOST=$(hostname)

# Set mail list
maillist="mymail@XXXXX.com"

# OPCSV
sudo /opt/OV/bin/OpC/opcsv -status > /tmp/Status.txt
echo -e -n "\n--------------------------------------" >> /tmp/Status.txt
echo -e -n "\nNumber of Process running on OVO Sever" >> /tmp/Status.txt
echo -e -n "\nNumber of OVO Action Agent Process opcacta Running: " >> /tmp/Status.txt
ps -ef |grep opcacta | grep -v grep | wc -l >> /tmp/Status.txt
echo -e -n "\nNumber of OMU Action Manager Process opcactm Running: " >> /tmp/Status.txt
ps -ef |grep opcactm | grep -v grep | wc -l >> /tmp/Status.txt
echo -e -n "\nNumber of OMU Forward Manager Process opcforwm Running: " >> /tmp/Status.txt
ps -ef |grep opcforwm | grep -v grep | wc -l >> /tmp/Status.txt
echo -e -n "\nNumber of OV Performance Core Process coda Running: " >> /tmp/Status.txt
ps -ef |grep coda | grep -v grep | wc -l >> /tmp/Status.txt

/bin/mailx -s "OVC Status for ${HOST} on ${DATE}" $maillist < /tmp/Status.txt
******************************************************************************


Request you all to help me out.

message edited by gjbedi


Report •

#8
March 18, 2015 at 12:23:54
In order to send email from Linux to the outside world, you need a mail transport agent. The most common one is send mail. You will need root privileges to set it up

This isn't my area, but you can read about it here:

http://www.linuxhomenetworking.com/...

message edited by nails


Report •

#9
March 18, 2015 at 13:16:15
Hi Nails,

Thanks for the swift response on this.

Sending mail is not the issue, the issue diffrent.
I want mail if there is any issue.


Report •

#10
March 19, 2015 at 08:44:11
I see output being redirected to a file /tmp/Status.txt and then you are mailing it. Sorry, but I don't see what your problem is.

Report •

#11
March 20, 2015 at 11:13:34
Hi Nails,

This script is working fine....

I want to modify this script to send me mail as and when required.

Like If any service is not running/ stopped in state or any process’s instance is more than 1 or less than 1, then I need it to send me a mail.


Report •

#12
March 21, 2015 at 22:55:22
For me to help, you require a more specific spec - like a list of commands you are interested in tracking.

Also, instead of grep'ing each line of the ps -ef command, look at field 9 to the end of the line:

#!/bin/ksh

# execute a 'ps -ef' command, pipe it to an awk script that prints out field
# 9 to the end of the line:
ps -ef | awk ' { for(i=9; i <= NF; i++)
           {
           printf ("%s ", $i)
           }
           printf ("\n")
} '

(the ps command is not very portable. On my Solaris 10 system, the name of the command starts at field 9 to the end of the line).

Once you have a list of executing commands from the ps -ef command, you can compare it against your list of commands to be tracked.

message edited by nails


Report •

Ask Question