473,402 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

using shell script

help ,please

using shell script
i want know the all process are running or not in a particular path.
the result will shown in web page (html).

process name = running ( server is running)
process name1 = not running( here server is not running)
process name 2 = running ( server is running)

above 3 lines shown in web page.

please help very urgent to me.
Apr 4 '08 #1
9 3492
prn
254 Expert 100+
using shell script
i want know the all process are running or not in a particular path.
the result will shown in web page (html).

process name = running ( server is running)
process name1 = not running( here server is not running)
process name 2 = running ( server is running)
The usual way of determining if a particular process is running is to us ps piped to grep for the process. For example, if you want to determine whether Apache is running, you can do something like:
Expand|Select|Wrap|Line Numbers
  1. ps | grep httpd
and get back some number of lines showing all the processes with httpd in them.

Perhaps unfortunately, one process line you are likely to get back will be "grep httpd". :)

So you may want to filter that out with something like
Expand|Select|Wrap|Line Numbers
  1. ps -ef | grep -v grep | grep httpd
And this will return only the lines showing actual instances of Apache. Now you are in a position to adapt this to your shell script (presumably being run by the web server---see below) where you just want to return a line saying that apache is or is not running. (You may notice something odd about the particular example I have chosen. :) )

Here, you don't really care about the exact content of the lines, in fact you probably don't want to actually display them. You just want a "count" of the number of lines returned so you know whether there were some or none:
Expand|Select|Wrap|Line Numbers
  1. if [ `ps -ef | grep -v grep | grep -c httpd` -gt 0 ] ; then
  2.         echo "<P>apache is running</P>"
  3.         exit
  4. else
  5.         echo "<P>apache is not running</P>"
  6.         exit
  7. fi
Now comes the warning: You need root privileges to look at processes being run by other users and your web server should NOT be running with root privileges. It will usually run either as "www" or as "nobody". So you need to grant LIMITED privs to the user that runs the web server. (I'll assume "www" for this example.) By far the best way to do this is to use sudo. Here is another thread with some discussion of how to go about that.

In this case, (let's assume desdemona is the name of your server) the easiest thing might be to put the actual script (let's call it foo.cgi) for this specific function directly into cgi-bin (which may be /usr/local/apache/share/cgi-bin, for example) and set the privs for it as:
Expand|Select|Wrap|Line Numbers
  1. chmod 0744 foo.cgi
so that only root can execute it and then include the lines:
Expand|Select|Wrap|Line Numbers
  1. # User privilege specification
  2. root    ALL=(ALL) ALL
  3. www     desdemona=NOPASSWD:/usr/local/apache/share/cgi-bin/foo.cgi
  4.  
in your /etc/sudoers file.

I know that this is probably more information and less "how-to" than you may have been hoping for, but in fact, it's not quite as simple as dropping in a pre-made script.

HTH,
Paul
Apr 4 '08 #2
Thaks very much Paul
one more thing. Below shell script i create all servers are running or not
but i wrote like
i create a file, name of the file is =input_file(in that file put the all servers name)
and run the scripts
getting out put like

SERVER NAME

NETXfnic_uas02_31008 = 1
NETXacs2_uas02_31011 = 0 (this name AMERICAN CENTURY2)
NETXnetxpress_uas02_31013 = 1 (this name NETXPRESS)
NETXjohnston_uas02_31035 = 1
NETXemerald_uas02_31039 = 1
NETXjapan_uas02_31044 = 1
NETXncbank_uas02_31073 = 1
NETXcunamutual_uas02_31069 = 1
NETXhibernia_uas02_31081 = 1

but i want OUTPUT like

AMERICAN CENTURY2 NOT RUNNING
NETXPRESS RUNNING

(NETXacs2_uas02_31011) this is the server name but output like AMERICAN CENTURY2 i want show in the web page


so many servers we have ,so we show the in the web page like
server name = running
server name1 = not running

AMERICAN CENTURY2 NOT RUNNING
NETXPRESS RUNNING

var=`cat input_file`

if [ -f ./out.htm ]
then
rm ./out.htm
fi

for list_of_proc in $var
do
echo $list_of_proc
ps -eaf | grep $list_of_proc >> ./out.htm >&1
done

for list_of_proc in $var
do
flag=`grep "NETXcppServer -name $list_of_proc" out.htm|wc -l`

startTag="<html><head></head><body><h1>"
endTag="</h1></body></html>"
echo "$startTag" "$list_of_proc" "=" "$flag" "$endTag" >> /u/mkulluru/dev/html/abc.htm
done

please reply me it help and carrier will good for me also

Regards,
Madhu















The usual way of determining if a particular process is running is to us ps piped to grep for the process. For example, if you want to determine whether Apache is running, you can do something like:
Expand|Select|Wrap|Line Numbers
  1. ps | grep httpd
and get back some number of lines showing all the processes with httpd in them.

Perhaps unfortunately, one process line you are likely to get back will be "grep httpd". :)

So you may want to filter that out with something like
Expand|Select|Wrap|Line Numbers
  1. ps -ef | grep -v grep | grep httpd
And this will return only the lines showing actual instances of Apache. Now you are in a position to adapt this to your shell script (presumably being run by the web server---see below) where you just want to return a line saying that apache is or is not running. (You may notice something odd about the particular example I have chosen. :) )

Here, you don't really care about the exact content of the lines, in fact you probably don't want to actually display them. You just want a "count" of the number of lines returned so you know whether there were some or none:
Expand|Select|Wrap|Line Numbers
  1. if [ `ps -ef | grep -v grep | grep -c httpd` -gt 0 ] ; then
  2.         echo "<P>apache is running</P>"
  3.         exit
  4. else
  5.         echo "<P>apache is not running</P>"
  6.         exit
  7. fi
Now comes the warning: You need root privileges to look at processes being run by other users and your web server should NOT be running with root privileges. It will usually run either as "www" or as "nobody". So you need to grant LIMITED privs to the user that runs the web server. (I'll assume "www" for this example.) By far the best way to do this is to use sudo. Here is another thread with some discussion of how to go about that.

In this case, (let's assume desdemona is the name of your server) the easiest thing might be to put the actual script (let's call it foo.cgi) for this specific function directly into cgi-bin (which may be /usr/local/apache/share/cgi-bin, for example) and set the privs for it as:
Expand|Select|Wrap|Line Numbers
  1. chmod 0744 foo.cgi
so that only root can execute it and then include the lines:
Expand|Select|Wrap|Line Numbers
  1. # User privilege specification
  2. root    ALL=(ALL) ALL
  3. www     desdemona=NOPASSWD:/usr/local/apache/share/cgi-bin/foo.cgi
  4.  
in your /etc/sudoers file.

I know that this is probably more information and less "how-to" than you may have been hoping for, but in fact, it's not quite as simple as dropping in a pre-made script.

HTH,
Paul
Apr 5 '08 #3
ghostdog74
511 Expert 256MB

Perhaps unfortunately, one process line you are likely to get back will be "grep httpd". :)

So you may want to filter that out with something like
Expand|Select|Wrap|Line Numbers
  1. ps -ef | grep -v grep | grep httpd
And this will return only the lines showing actual instances of Apache.l
don't have to use that many greps, when awk does the job :)
Expand|Select|Wrap|Line Numbers
  1. ps -ef| awk '/httpd/'
  2.  
Apr 6 '08 #4
prn
254 Expert 100+
don't have to use that many greps, when awk does the job :)
Expand|Select|Wrap|Line Numbers
  1. ps -ef| awk '/httpd/'
  2.  
Eh?

Expand|Select|Wrap|Line Numbers
  1. [root@deimos ~]# ps -ef | grep 'bash'
  2. prn       2915  2912  0  2007 pts/1    00:00:00 bash
  3. root      2949  2944  0  2007 pts/1    00:00:00 -bash
  4. prn      22993 22984  0 Mar07 pts/2    00:00:00 bash
  5. prn      26492 26491  0 12:54 pts/3    00:00:00 -bash
  6. root     26526 26525  0 12:54 pts/3    00:00:00 -bash
  7. root     26581 26526  0 12:57 pts/3    00:00:00 grep bash
  8. [root@deimos ~]# ps -ef | grep -v grep | grep -c bash
  9. 5
  10. [root@deimos ~]# ps -ef | awk 'bash'
  11. [root@deimos ~]#
If, in those circumstances, I grep just for "bash", I get back 5 instances plus the grep itself. If I use -v to exclude the "grep" line, I get back the proper count. If I use the awk expression you gave, I am getting back nothing.

I could always use something like:
Expand|Select|Wrap|Line Numbers
  1. [root@deimos ~]# ps -ef | awk /bash/
  2. prn       2915  2912  0  2007 pts/1    00:00:00 bash
  3. root      2949  2944  0  2007 pts/1    00:00:00 -bash
  4. prn      22993 22984  0 Mar07 pts/2    00:00:00 bash
  5. prn      26492 26491  0 12:54 pts/3    00:00:00 -bash
  6. root     26526 26525  0 12:54 pts/3    00:00:00 -bash
  7. root     26614 26526  0 13:06 pts/3    00:00:00 awk /bash/
  8.  
but that is simply equivalent to the case of "ps -ef | grep bash" so I'm not clear on what you mean there.

Paul
Apr 7 '08 #5
prn
254 Expert 100+
Thaks very much Paul
one more thing. Below shell script i create all servers are running or not
but i wrote like
i create a file, name of the file is =input_file(in that file put the all servers name)
and run the scripts
getting out put like
Sorry, Madhu. I am having trouble figuring out what you mean. Can you rephrase your question? And please use "code" tags around your code. I'm not clear on what you're getting, what you want and why. Let's try to get one point at a time. It looks like you're trying to ask several questions together and I'm not understanding which is what.

Paul
Apr 7 '08 #6
ghostdog74
511 Expert 256MB
but that is simply equivalent to the case of "ps -ef | grep bash" so I'm not clear on what you mean there.
Paul
sorry, i did not finish the code...
here's what i meant
Expand|Select|Wrap|Line Numbers
  1. # ps -ef | awk '/bash/ && !/awk/'
  2.  
you don't have to call another grep process just to remove the extra "grep". however, it doesn't matter really..some people have gotten used to grep -v grep. :)
Apr 8 '08 #7
prn
254 Expert 100+
Ah! I see now. Yes, that is a bit more elegant. :)

Paul
Apr 8 '08 #8
Ah! I see now. Yes, that is a bit more elegant. :)

Paul
we have 40 sites each site haveing webserver setup and application servers.
and also we need to find out the each site webserver and application servers is running or not in a particular machine.

if 40 sites are running or not running show in the html page.

These input_file have the 40 sites name


var=`cat input_file`

if [ -f ./out.htm ]
then
rm ./out.htm
fi

for list_of_proc in $var
do
echo $list_of_proc
ps -eaf | grep $list_of_proc >> ./out.htm >&1
done
for list_of_proc in $var
do
flag=`grep "NETXcppServer -name $list_of_proc" out.htm|wc -l`
startTag="<html><head></head><body><h1>"
endTag="</h1></body></html>"
echo "$startTag" "$list_of_proc" "=" "$flag" "$endTag" >> /u/mkulluru/dev/html/abc.htm
done



i am getting out

Republic = 1
TRP = 0
(here 1 mean is running)
(here 0 mean is not running)


but i want put like

Republic = running
TRP = Not running

how can write the in the script , please on this it is very use full to me.

Thanks & Regards
Madhusudhana gupta kulluru
May 13 '08 #9
i giving full details,

we have machines a,b,c,d
in each machine application servers are running
but each machine have 40 application server are running
result of 40 application servers are running or not shown in the web page.


but i am in z machine
when run the script (http://172.30.98.91:/cgi/health.ksh) in web page
Result will show in the web page .

Resultant in web page


Server a machine b machine c machine d machine
--------------------------------------------------------------------------------------------
trowe running running running running
republic running not running running running
universal not running
. ,
.
. ,
.
.
acs running running running running


it very help full greate becaues i am trouble .please help

Thanks & Regards,
Madhusudhana gutpa kulluru









we have 40 sites each site haveing webserver setup and application servers.
and also we need to find out the each site webserver and application servers is running or not in a particular machine.

if 40 sites are running or not running show in the html page.

These input_file have the 40 sites name


var=`cat input_file`

if [ -f ./out.htm ]
then
rm ./out.htm
fi

for list_of_proc in $var
do
echo $list_of_proc
ps -eaf | grep $list_of_proc >> ./out.htm >&1
done
for list_of_proc in $var
do
flag=`grep "NETXcppServer -name $list_of_proc" out.htm|wc -l`
startTag="<html><head></head><body><h1>"
endTag="</h1></body></html>"
echo "$startTag" "$list_of_proc" "=" "$flag" "$endTag" >> /u/mkulluru/dev/html/abc.htm
done



i am getting out

Republic = 1
TRP = 0
(here 1 mean is running)
(here 0 mean is not running)


but i want put like

Republic = running
TRP = Not running

how can write the in the script , please on this it is very use full to me.

Thanks & Regards
Madhusudhana gupta kulluru
May 16 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Chuck Anderson | last post by:
Can anyone point me in the right direction? I want to use Php to automate confirmation of someone joining an email list by them replying to an email (so they don't have to have a browser?). I...
0
by: Aashif | last post by:
I want to call Unix Shell script which is available in other Server (Unix server) from windows application using C#. Currently the shell script runs the C program but the GUI is not good, So I want...
4
by: DyslexicAnaboko | last post by:
Hello, I have a module that is part of larger project that is giving me trouble, so I setup an example. Brief ===== I simply want to open a text file and make the contents avaliable...
6
by: Sanket80 | last post by:
Hi, I have one shell script which runs a report and sends the output to user. The shell script has some queries written in it in SQL and hence when I execute a shell script via a concurrent...
9
by: niteck07 | last post by:
I am using following shell script to ftp files to another server but this is failing as the shell script changes the user name for the ftp login the correct user name is 'ag\invprint' which the...
3
by: telduivel | last post by:
Can someone please help me with this: I have a python script, that at some point calls a linux bash script (.sh). Starting the shell script is the last thing my python script needs to do, so I...
1
by: ksn2007 | last post by:
Hi All, I have to run a shell script from my php script and while shell script is running I have to do some other tasks in my php script.To run the shell script I am using ...
5
by: Hul Tytus | last post by:
comp.lang.c c programs & shell conditionals How is a unix shell script made to respond to the value returned by a program compiled from c code? The shell script below is my current effort,...
16
by: pereges | last post by:
Do you see anything wrong about this method ? For eg. I write a shell script a.sh containing : cc -o test file1.c file2.c file3.c and then execute the shell script ( sh a.sh) to compile and...
7
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.