if ps -p 1234 reports nothing, echo something


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting if ps -p 1234 reports nothing, echo something
# 1  
Old 04-24-2012
if ps -p 1234 reports nothing, echo something

I have a script that I need to put in some checking. It would read something like this but I need help with the exact notation:

Code:
#!/bin/bash
while true
if [ -z `ps -p 1234` ] #process is no longer reporting as up
echo "process 1234 has fell"
exit 1 # exit script
fi
sleep 1
#end of script

Any help greatly appreciated

Smilie

Last edited by methyl; 04-24-2012 at 05:15 PM.. Reason: pleaes use code tags
# 2  
Old 04-24-2012
There is a lot of variation in the ps command.
Please post a sample command and output for a process which does exist and a process which does not exist. If you can find one on your system, please also post a sample for a zombie process.
The usual problem with processing the output from ps is disposing of the column headings.
# 3  
Old 04-24-2012
Code:
#!/bin/bash

pid=${1:?Usage $(basename $0) pid}
while true
do
    if ! kill -0 $pid 2>/dev/null; then #process is no longer reporting as up
        echo "process $pid has fell"
        exit 1 # exit script
    fi
    sleep 1
done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

RSYSLOG reports

I want to create reports using rsyslog in linux,Can someone help me out here ? Report Format must be "Hostname" "Username" "Hostname logged from" "Date" "Time" Regards, Ahmed. ---------- Post updated at 05:24 PM ---------- Previous update was at 05:24 PM ---------- Linux,Shell Script (10 Replies)
Discussion started by: ahmed.vaghar
10 Replies

2. Shell Programming and Scripting

Add "1234" to specific field in second column

i have this file 073274753,0544901701,20101201,000316 038873722,69647455,20101130,235257 26213399,0545335767,20101201,000930 063330167,0566000101,20101201,000226 026773376,11966,20101130,234429,1194 075431120,0565900600,20101201,000428 75431120,0565900600,20101201,000538... (6 Replies)
Discussion started by: maxim42
6 Replies

3. Red Hat

intodns.com reports old IP

Hello, I have this problem: I have a domain which worked well until my ISP changed my ip. Since then my DNS is not working, and intodns.com reports still the old IP. The DNS remains the same. I made changes in named.conf, in ifcfg-Auto_eth0, I flushed the cache but it;s the same thing. What... (6 Replies)
Discussion started by: doe_ro
6 Replies

4. UNIX for Dummies Questions & Answers

sendmail[1234]: [ID 702911 mail.alert] dowork: sl_hrtob failed

When changing my server back as the mail server, I get the following error: sendmail12345]: dowork: sl_hrtob failed When looking at previous posts similar to my issue, none of them work. I do not have DNS and have ensured that the mail domain is correct. Can anyone else help out with... (2 Replies)
Discussion started by: PuterGirl5
2 Replies

5. Shell Programming and Scripting

With that logic this echoes "echo". Question about echo!

echo `echo ` doesn't echoes anything. And it's logic. But echo `echo `echo ` ` does echoes "echo". What's the logic of it? the `echo `echo ` inside of the whole (first) echo, echoes nothing, so the first echo have to echo nothing but echoes "echo" (too much echoing :P):o (2 Replies)
Discussion started by: hakermania
2 Replies

6. UNIX for Dummies Questions & Answers

How to find all files containing "1234" in their inode number?

Hi, if there are 3 files with the following inode numbers: 012345 012346 012347 is there a way to find all those files containing "1234" as inode? i found out that i cant use any wildcards. or i just didnt put them in the right way. find . -inum ... ? thanks 4 help. devil (2 Replies)
Discussion started by: daredevil82m
2 Replies

7. UNIX for Dummies Questions & Answers

How to correctly use an echo inside an echo?

Bit of a weird one i suppose, i want to use an echo inside an echo... For example... i have a script that i want to use to take users input and create another script. Inside this script it creates it also needs to use echos... echo "echo "hello"" >$file echo "echo "goodbye"" >$file ... (3 Replies)
Discussion started by: mokachoka
3 Replies

8. Shell Programming and Scripting

Difference between using "echo" builtin and /bin/echo

So in my shell i execute: { while true; do echo string; sleep 1; done } | read line This waits one second and returns. But { while true; do /bin/echo string; sleep 1; done } | read line continues to run, and doesn't stop until i kill it explicitly. I have tried this in bash as well as zsh,... (2 Replies)
Discussion started by: ulidtko
2 Replies

9. HP-UX

Hp-ux 11.11 and Oracle reports

HI I am battling to find why oracle reports dont work from the Oracle applications and work from the Command line Finally, whern these reports error out in the Oracle apps, I see the error that the x server killed the process. Please let me know if any one has some chi-chi sheet on the os setup... (1 Reply)
Discussion started by: schilukuri
1 Replies

10. UNIX for Dummies Questions & Answers

telnet myhost 1234 cant work?

in myhost, i did a telnet myhost 1234, but got the below Trying... Connected to myhost. Escape character is '^]'. and just waits there... in /etc/services i had the following sftp 1234/tcp then in my /etc/inetd.conf i had sftpd stream tcp nowait meuser /usr/sftpd sftpd ... (13 Replies)
Discussion started by: yls177
13 Replies
Login or Register to Ask a Question