HOWTO: Conky – IP monitor

20Dec09

So, last night I strung together (with some help from here) a script for conky that will ping IPs, and send back a success or failure statement, letting me see what computers are on at any given time. This assumes you have  a working Conky, I’m not going into that right now. Theres plenty of tutorials, Google em.

Conky IP monitorThe script is named .pingtest.sh, so it’s hidden, and its in my home directory.

#!/bin/bash

if ping -c 1 -W 2 $1 > /dev/null; then
echo "Up"
else
echo "Down"
fi

It’ll ping one packet only (-c 1) and has a timeout of 2 seconds, (-W 2), meaning that if no reply is given in two seconds, its a fail. The /dev/null part gets rid out the output of ping. “Up” is what is returned if the ping is successful, “Down” if its not. Change to your liking. Make sure the script is executable by running

chmod +x .pingtest.sh

The $1 part refers to the original command, so if you call it with “.pingtest.sh 192.168.1.1″, it’ll ping 192.168.1.1.

To add it to conky, use

${execi 10 ~/.pingtest.sh XXX.XXX.XXX.XXX}

Execi means Execute at an Interval, here every 10 seconds. ~./pingtest.sh is the script (~/ meaning home) and replace the XXs with the IP address.

If you want to add Conky variables to the script, for example, ${color}, to change the colour of the value returned, green for “Up”, red for “Down”, whatever you like, you’ll need to tell Conky to parse the script. To do that, replace “execi” with “execpi”. Then you can add Conky variables to the script, and have them show on your conky :)

For those who are interested, the command to find external IP address as shown is

${execi 60 curl http://riivo.eu/php/ip.php}

Make sure you have curl installed first though

sudo apt-get install curl

Thats it :)

About these ads


8 Responses to “HOWTO: Conky – IP monitor”

  1. 1 PHATMiND

    Awesome ! just what i was looking for.

    but if it possible to to make the word “up” in red or some other color ?

    i tried to put ${color red}”up” in the .pingtest.sh, but that didn’t work obviusly =D

    • 2 evidex

      You can, you can put in things like ${color red}, just make sure that when you execute it in conky, do so with execp. That parses the information it’s fed, so you can insert things like ${color red}. For one which executes at an interval, use execpi. Man conky for more information =]

  2. 3 blu

    Thanks.

  3. 4 sasagundul

    nice script :D

    thanks.

    on request: is there any possible way to make the script ping to the computer behind router. so i can ping my computer remotely :D

    • 5 evidex

      I can think of two ways. The first, and most simple is to setup your computer with a static IP, and pass it through the router, in the same way you would if you were going to host a web page. That would require you speaking to you ISP to get a static IP, which isn’t always possible or feasible. Then you could simply set the script to ping that address.

      Another way that might work would be to sign up to DynDNS. This service provides a free domain, assigned to your computer. You’ll need to install some software on your computer, which will sync with you DynDNS account, and send it your current IP address. This allows people to host a website from a dynamic IP address. You’ll still need to setup your router to allow the requests to pass through, but then you could simply ping the domain you get (yourdomain.whatever), and that would actually ping your computer I believe. I’m not entirely sure on that though. Here’s a guide to using DynDNS in Ubuntu. I hope this has helped, or at least given you an idea.

      https://help.ubuntu.com/community/DynamicDNS

  4. 6 sasagundul

    thanks for your reply.

    I’ve tried using DynDNS but still no luck. seems like my router is blocking ping access from outside the network. i search google and someone told me that i have to disable firewall in my router. guess i will take a look at my router configuration first.

    thanks

    • 7 evidex

      You’ll probably need to forward the HTTP port through your router. This site should help you.

  5. 8 sasagundul

    hey :D i got a good news for you. i’m finally made this thing working with my computer.
    the key is you have to setup a web server on your remote machine.

    i modified your script to not to ping the server address but to grab file from the server and make the output as a signal that the computer is online :D

    it’s very easy. you just have to put a small file in your server and fetch the file.

    thanks



Follow

Get every new post delivered to your Inbox.

Join 68 other followers

%d bloggers like this: