?
Solved

Shell script, evaluate if ps command not null

Posted on 2014-08-14
1
Medium Priority
?
402 Views
Last Modified: 2014-08-14
Using shellscript, how do i evaluate wether a "ps" command returns a null result (nothing) or something??

If it returns something i will execute some other command

if it doesn't return a thing, i will execute another...

how do i do this?

If( "ps...." = null) ...???
0
Comment
Question by:celtician
1 Comment
 
LVL 40

Accepted Solution

by:
omarfarid earned 2000 total points
ID: 40261191
try this

if the ps command fails then it returns non-zero exit status. you can find it from env $?

e.g.

ps -u myuser
if [ $? -ne 0 ]
then
       runcommand1
else
       runcommand2
fi
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses
Course of the Month14 days, 6 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question