1754355 Members
4452 Online
108813 Solutions
New Discussion

shell help

 
SOLVED
Go to solution
chin hyeon jung
Advisor

shell help

I made shell script finding process
but I return wrong result
help me!!
#!/usr/bin/sh
echo "pid="
read my_pid
ps -ef|while read UID PID PPID DUMMY
do
if [ $my_pid == $SPID]
then
echo "WE FOUND ${my_pid} IS $SPID"
fi
done


1253
./j[7]: test: Specify a parameter with this command.
./j[7]: test: Specify a parameter with this command.
./j[7]: test: Specify a parameter with this command.
.
1 REPLY 1
S.K. Chan
Honored Contributor
Solution

Re: shell help

Try this .. I made some modification ..

#!/usr/bin/sh
echo "pid= \c"
read my_pid

for PID in `ps -ef|sed 's/^ *//g'|grep -v \^UID|awk '{print $2}'`
do
if [ $my_pid -eq $PID ]
then
echo "WE FOUND $my_pid IS $PID"
fi
done

The "ps -ef" is first filtered by removing spaces from begining of each line. Then pass that to "grep -v \^UID" to take away the first line starting with UID and then print out 2nd field which is the UID.