SunQuest
           Server Administration
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesServer Administration

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
You eat, breathe and sleep innovation. Build your mobile intelligence with BlackBerry® experts this July. Register Today!
  #1  
Old July 1st, 2003, 11:11 AM
staffan.svedin staffan.svedin is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Nora, Sweden
Posts: 4 staffan.svedin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
detect a running process

Hi!

Trying this forum for help with my script.

Running AIX and script is Kornshell.

My goal is to automate installation of program modules, mainly Perl and Kornshell.

I've got an old script doing the following to detect a running program (which will not be installed as it is currently running).

My question is:
1)
Will it work?
(I have tried it but it doesn't seem to deliver the right output.)

2)
What exactly does the "sed"
part do?

3)
Is there a better way?

code:
pattern=$( print $program | sed -e ´s!^.![ /][&]!´ -e ´s/$/[ $]/´
ps -ef | grep -v $PROGRAM | grep "$pattern" >/dev/null && log "Unable to install, $program is running" || installroutine

//Best regards

Reply With Quote
  #2  
Old July 2nd, 2003, 01:11 PM
staffan.svedin staffan.svedin is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Nora, Sweden
Posts: 4 staffan.svedin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: detect a running process

Sorry if I took your time,
now it's running.
//Staffan

Reply With Quote
  #3  
Old July 23rd, 2003, 02:00 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
RE: detect a running process

try:

#!/bin/sh
PROC=`ps -ef | grep <process> | grep -v ${0} | sed -e 'print $2'`

if [ ${PROC} ] ;; then
echo "proc is running"
fi

You'll need to swap out the <process> with whatever you are checking for. 'ps -ef' might need to change, based on your OS. Under Linux, for example, you want 'ps -aux'. You also may need to switch out the 'sed -e 'print $2', and change the $2 to a different column. If you do a ps -aux, you want the column of the pid to be reflected by this. The counting starts at 1, instead of 0, so the first column listed will be $1. I know this script isn't ksh, but I think it'll work there.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesServer Administration > detect a running process


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway