As your "sample pipe" doesn't represent a sensible, runnable code (due to semantical and syntactical errors), please present any attempts from your side. What ps fields should be matched? How are the patterns transported / presented - your assignment samples won't work either?
Hi,
Here is my sample code, i would like filter the output to list only the not running/matching services...
u=u_user
srvc='ps -aef |egrep -i "ABC|abc_xyz_exe|abc_cde|abc.agent.app|ABC abc"|grep -v grep'
for host in $(cat srv.lst)
do
ping -c2 -w3 "$host" > /dev/null
if [ $? -eq 0 ]; then
echo "Connecting to $host and getting the process list \n"
ssh $u@$host $srvc
else
echo "$host is not available"
fi
done
u=u_user
srvc='ps -aef'
patterns="sleep|ABC|abc_xyz_exe|abc_cde|abc.agent.app|ABC abc"
oldIFS=$IFS
for host in $(cat srv.lst)
do
if ping -c2 -w3 "$host" > /dev/null; then
echo "Connecting to $host and getting the process list \n"
pslist=$(ssh $u@$host $srvc)
IFS=\|
for pattern in $patterns;
do
case $pslist in
(*"$pattern"*)
:
;;
(*)
echo "Service \"$pattern\" is not running"
;;
esac
done
IFS=$oldIFS
else
echo "$host is not available"
fi
done