Issue
./tesh.sh 192.168.1.10 elastic01
# this is script
ip=$1
node=$2
pid=`ps -ef | grep $node | grep -v "grep" | awk '{print \$2}'`
echo $pid
run this script output:
2234 (I want to get)
2313
3241
Solution
If you want just the top entry, use
awk 'NR==1 { print $2 }'
Process only the first line with NR==1 and print only the second space delimited field.
Answered By - Raman Sailopal Answer Checked By - Terry (WPSolving Volunteer)