perl scripting for checking if a process is running


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers perl scripting for checking if a process is running
# 1  
Old 10-03-2008
perl scripting for checking if a process is running

Hi All,

I am new to perl and have been trying to write a short script to check a process.Though i havent reached to the stage where i can match the output.
I am trying to pass a variable x with value /opt/RGw/csbp-base/CSBP_BAT.01.00.05/csbp_BAT.01.00.05.jar

and then pass another variable y to check if the process is running in the system

ps -ef | grep -i "csbp_BAT.01.00.05.jar" | grep -v grep |awk -F" " '{print $11}'
Though this command works from the command line.but if i run and print the same via the script i get all messed up

#!/usr/bin/perl
$x="/opt/RGw/csbp-base/CSBP_BAT.01.00.05/csbp_BAT.01.00.05.jar";
$y=`ps -ef | grep -i "csbp_BAT.01.00.05.jar" | grep -v grep |awk -F" " '{print $11}'`;
print "\n";
print "$x \n";
print " \n";
print "$y";
print "\n";
#echo $y;
#if [$x=$y]#then
# echo "1st step completed"
# echo "let me try somemore"
#else
#echo "try again"
#echo "will need to see how it works"
#fi
#exit


Thanks in advance for clearing my doubts.

Br///
pistachio
# 2  
Old 10-04-2008
If you have fuser or lsof on your system coding that is easier than grepping thru ps -ef output....
Code:
perl -e ' if(len("$ARGV[0])> 0) { 
                  print " found\n" 
             } else 
               {print "not found\n"}; \
              "$(lsof -F u /opt/RGw/csbp-base/CSBP_BAT.01.00.05/csbp_BAT.01.00.05.jar 2>/dev/null)"

# 3  
Old 10-04-2008
It's not clear to me what the problem is, though. To compare two strings, use the eq operator. Remember to chomp the output from the backticks, though.

The ps script could really be simplified a lot. Why not code it to only print if the value of $11 is exactly what you want in the first place?

Code:
ps -ef | awk '$11 == "/opt/RGw/csbp-base/CSBP_BAT.01.00.05/csbp_BAT.01.00.05.jar"'

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Command to get exact tomcat process I am running ignoring other java process

Team, I have multiple batchjobs running in VM, if I do ps -ef |grep java or tomcat I am getting multiple process list. How do I get my exact tomcat process running and that is unique? via shell script? (4 Replies)
Discussion started by: Ghanshyam Ratho
4 Replies

2. UNIX for Beginners Questions & Answers

How to display only the first 5 running process using top in shell scripting?

topfunc() { top } topfunc Here i used the top command inside a function,and i called the function. when executing this bash file i get all the process which are using by the kernel i just want to display only the first 5 running process. is it possible? (7 Replies)
Discussion started by: Meeran Rizvi
7 Replies

3. UNIX for Advanced & Expert Users

Process remians in Running state causing other similar process to sleep and results to system hang

Hi Experts, I am facing one problem here which is one process always stuck in running state which causes the other similar process to sleep state . This causes my system in hanged state. On doing cat /proc/<pid>wchan showing the "__init_begin" in the output. Can you please help me here... (6 Replies)
Discussion started by: naveeng
6 Replies

4. UNIX for Advanced & Expert Users

Process remians in Running state causing other similar process to sleep and results to system hang

Hi Experts, I am facing one problem here which is one process always stuck in running state which causes the other similar process to sleep state . This causes my system in hanged state. On doing cat /proc/<pid>wchan showing the "__init_begin" in the output. Can you please help me here... (1 Reply)
Discussion started by: naveeng
1 Replies

5. BSD

Process remians in Running state causing other similar process to sleep and results to system hang

Hi Experts, I am facing one problem here which is one process always stuck in running state which causes the other similar process to sleep state . This causes my system in hanged state. On doing cat /proc/<pid>wchan showing the "__init_begin" in the output. Can you please help me here... (0 Replies)
Discussion started by: naveeng
0 Replies

6. Shell Programming and Scripting

Checking running process status using "grep" on multiple servers in load sharing system.

Suppose i have 3 different servers say x,y and z. Im running some process say ABC and 40 instances for the same is being created. In load sharing suppose on server x, 20 instances are running server y, 10 instances are running server z, 10 instances are running. While checking the... (1 Reply)
Discussion started by: ankitknit
1 Replies

7. UNIX for Dummies Questions & Answers

Checking Unix Performance - Why is a process running slowly?

Hi Please can someone explain to me how they would go about monitoring the performance of a process in Unix. Lets say that a user is running a process in Unix but it seems to be taking a long time, whereas it completed a lot quicker yesterday. How would you go about investigating what is causing... (1 Reply)
Discussion started by: Sunny Sid
1 Replies

8. Shell Programming and Scripting

perl process loop isn't running

I'm trying to figure out why the perl process we have running in a loop isn't working. Basically its setup to read our queue from Amazon SQS with the results getting inserted into the db. We are using EC2 for video transcoding and once the conversion takes place our web server hosted outside... (10 Replies)
Discussion started by: kwick6
10 Replies

9. Shell Programming and Scripting

script to monitor process running on server and posting a mail if any process is dead

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)
Discussion started by: pradeepmacha
13 Replies

10. Shell Programming and Scripting

checking for a running process from korn cron

cron starts a job every 10 minutes via a korn shell - I need to determine if the previous process is still running before I allow the new process to start - HELP I've tried ps -ef, etc but I have seen many situation where it says that the is running when it is not - any ideas on how to absolutely... (2 Replies)
Discussion started by: jph
2 Replies
Login or Register to Ask a Question