Re: grep & egrep script problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Paul Ward wrote:
...
I am wanting to find multiple proccess and then produce a true exit
code if they are all there and a false if they are not.
...

It might make things simple if you use ps to do the selection as well. Since you seem to know the PIDs you're looking for, you can ask ps to look for them specifically. Unfortunately, it won't return an error if any are missing, but you can have it print the ones it finds, and see if you get the same number out as you put in:

------- snip -------
#!/bin/sh

# the PIDs we want to check
PIDS='2530 2514 4016 4017'

XPIDS=`ps --no-headers -o pid -p "$PIDS"`

if [ `echo "$XPIDS" | wc -l` = `echo $PIDS | wc -w` ]
then
  echo "All PIDs present: ($PIDS)"
else
  echo "Something's missing: need ($PIDS), found (`echo $XPIDS`)"
fi
------- snip -------

I tried to stick with generic sh and avoid any bash-isms.

Here's what it looks like on a run:

$ sh -x tmp/fpids.sh
+ PIDS='2530 2514 4016 4017'
++ ps --no-headers -o pid -p '2530 2514 4016 4017'
+ XPIDS=' 2514
 2530
 4016'
++ echo ' 2514
 2530
 4016'
++ wc -l
++ echo 2530 2514 4016 4017
++ wc -w
+ '[' 3 = 4 ']'
++ echo 2514 2530 4016
+ echo 'Something'\''s missing: need (2530 2514 4016 4017), found (2514 2530 4016)'
Something's missing: need (2530 2514 4016 4017), found (2514 2530 4016)

--
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux