Mohammedz.com

For Linux and Shell scripting.

How to check uptime of any service running a Linux machine?

1 Comment


This bash script should help you to find uptime of any service running in a Linux machine.

#! /bin/bash

SERVICE=”$1″

if [[ $# -eq 1 ]]; then
result=`ps -eo “%U %c %t” |grep “$SERVICE” |grep -v grep| grep root`
uptime=`echo $result |awk ‘{ print $NF }’`

if [[ -n $uptime ]]; then
echo “”
echo “$SERVICE uptime is $uptime”
echo “”
else
echo “”
echo “$SERVICE is not running currently”
echo “”
fi
else
echo “”
echo “Usage: `basename $0` <service name>”
echo “This will print how long the service is running”
echo “”
fi

Advertisements

One thought on “How to check uptime of any service running a Linux machine?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s