Script to check running processes on remote server.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to check running processes on remote server.
# 1  
Old 10-04-2006
Script to check running processes on remote server.

Hi,

I am trying to write a script, which queries a db to get the names of processes, stores it in a file and then checks if that process is running on a remote server. However I am not getting it right, could anyone help me out.


#!/bin/sh
echo "select Address from Device where Cust = '3-136VFF' and State = -2" | mysql Pen | grep -v Address > ./ge1
cat ./ge1 | \
while read line
do
a = ""
a = $(`rsh ontrack 'ps -ef | grep -v grep | grep $line' | awk '{print $2}'`)
if[$a -eq ""]; then
echo "process for $line not running";
done


Thanks,
Amit
# 2  
Old 10-04-2006
Quote:
Originally Posted by amitsayshii
Hi,

I am trying to write a script, which queries a db to get the names of processes, stores it in a file and then checks if that process is running on a remote server. However I am not getting it right, could anyone help me out.


#!/bin/sh
echo "select Address from Device where Cust = '3-136VFF' and State = -2" | mysql Pen | grep -v Address > ./ge1
cat ./ge1 | \
while read line
do
a = ""
a = $(`rsh ontrack 'ps -ef | grep -v grep | grep $line' | awk '{print $2}'`)
if[$a -eq ""]; then
echo "process for $line not running";
done


Thanks,
Amit
i dont know. others may disagree with this but to me its always a very good idea to specify the path to any file/script that your script is going to be running or working on. cat ./gel can cause potential unnecessary headaches.

cat /path/to/file/gel is always better than cat ./gel
Terrible
# 3  
Old 10-05-2006
Thanks for you advise....I will be implementing that in the final script.....I am still testing it...
# 4  
Old 10-05-2006
trying a different approach...but still some errors in it....any help will be highly appreciated....

#!/bin/ksh
for I in `echo "select Address from Dev where Cust = '3-136VFF' and State = -2" | mysql Pen`; do
ip=`rsh ont 'ps -ef | awk '{print $9}' | grep -x $I`
if [ $I -ne $ip ]; then
echo "process for Ip $I not running" >> /tmp/getmon
fi
cat /tmp/getmon
done
# 5  
Old 10-05-2006
That's not enough information (at least for me). Could you post an example of:
"`echo "select Address from Dev where Cust = '3-136VFF' and State = -2" | mysql Pen`"
output?
Anyway, change your if and use:
Code:
if [[ "$I" !=  "$ip"]]; then

If you are comparing strings.

And take into account that you are assuming that both "select" and "rsh" are working and returning valid data...

Regards.
# 6  
Old 10-06-2006
Hi,

The ip variable is not getting the values. $I has the values
ip=`rsh ont "ps -ef | awk '{print $9}' | grep -x $I"`
is there any prob with the quotes ?

Thanks,
Amit
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Check processes running on remote server

Hello Guys, I need some help to find out if processes are running on remote server or not. I could do 'ssh' to do that but due to some security reasons, I need to avoid the ssh & get result from remote server. Could you please suggest some that can be done without ssh or similar sort of... (8 Replies)
Discussion started by: UnknownGuy
8 Replies

2. Shell Programming and Scripting

How to Append the output of a script running in remote server to a file in local server?

Hi guys, So i am in server1 and i have to login to server 2, 3,4 and run some script there(logging script) and output its result. What i am doing is running the script in server2 and outputting it to a file in server 2 and then Scp'ing the file to server1. Similarly i am doing this for other... (5 Replies)
Discussion started by: srkmish
5 Replies

3. AIX

Need to check long running processes on the database server and the os is AIX

Hello, Please help me with a script with which I can check long running processes on the database server and the os is AIX. Best regards, Vishal (5 Replies)
Discussion started by: Vishal_dba
5 Replies

4. Shell Programming and Scripting

Running script on remote server

Hi All, I need to run a ksh script on around 200 servers(consisting of AIX,LInux,HP-UX,Solaris). The script is there in the /tmp directory of all the servers. I want want to execute the script in background on the respective servers and then exit from there. I have written something like below:... (8 Replies)
Discussion started by: proactiveaditya
8 Replies

5. Shell Programming and Scripting

check web server running on local and on remote machine

Hi , How to check whether web server is running from remote machine How to check whether web server is running on web server itself Can any one help me soon (1 Reply)
Discussion started by: satheeshkr_cse
1 Replies

6. Shell Programming and Scripting

Running a function on a remote server via SSH in a script

I'm working on a script (mostly for practice) to simplify a task I have to do every now and then. I have a cluster with 6 servers on it, each server has a directory with a set of files called *.pid and *.mpid. Each file contains the pid of a process that may or may not be running on that server.... (3 Replies)
Discussion started by: DeCoTwc
3 Replies

7. Shell Programming and Scripting

How to stop a script running in remote server from local script

Hi, I have googled for quite some time and couldn't able to get what exactly I am looking for.. My query is "how to stop a shell script which is running inside a remote server, using a script"??? can any one give some suggestions to sort this out. (1 Reply)
Discussion started by: mannepalli
1 Replies

8. Shell Programming and Scripting

Running a Script in a Remote server

I am trying to write a script that would let me run a command in a remote server using ssh. scriptA: (dcm2nii is a command that only works on the other server) dcm2nii a b c scriptB: (I run this one on the current server) ssh -X otherserver /home/abc/Desktop/scriptA But when I do ... (2 Replies)
Discussion started by: ZeroGPX
2 Replies

9. Shell Programming and Scripting

Running a remote Server through perl script

Hello people, I am want to run a server on remote machine through perl scripting using telnet api. Now when I try to do so, the server gets started perfectly, but as soon as I close the telnet connection in the script, the server started on the remote machine suddenly goes down. I also... (0 Replies)
Discussion started by: chandrak
0 Replies

10. Shell Programming and Scripting

running a script on remote server.

I need to run a script on a remote server from my ksh script. The issue I'm having is that I need to logon to the remote server as a different user. (see the following) logged on to server 1 as adsmgr neet to log on to server 2 as odemgr run passwd_util.ksh Thanks in advance. (1 Reply)
Discussion started by: whited05
1 Replies
Login or Register to Ask a Question