Shell script, evaluate if ps command not null

Posted on 2014-08-14
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) ...???
Question by:celtician
    1 Comment
    LVL 40

    Accepted Solution

    try this

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


    ps -u myuser
    if [ $? -ne 0 ]

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
    I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (…
    Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
    This tutorial goes over how to archive and restore FreeBSD jails that are managed by ezjail.

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now