1751920 Members
4811 Online
108783 Solutions
New Discussion

Re: Sample Script

 
SOLVED
Go to solution
Ajin_1
Valued Contributor

Sample Script

Hi

 

What does the below said Scrips Explanation.

 

ps -ex | grep -v grep | grep "self test" > /dev/null 2>&1

if [ "$?" -eq 0 ]; then
    echo "0"
else
    echo "1"
fi

Thanks & Regards
Ajin.S
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
2 REPLIES 2
Solution

Re: Sample Script

Are you asking what this script snippet does?

 

If so, it will print "0" to stdout if it finds a process in the system process table that contains the string "self test". If it doesn't find a process that contains the string "self test" it will print a "1" to stdout

 


I am an HPE Employee
Accept or Kudo
Dennis Handly
Acclaimed Contributor

Re: Sample Script

You can optimize this so you only have one grep:

ps -ex | grep -q "[s]elf test"

 

Also you might want to change the echoes to something more meaningful:

echo "Found process: 0"