Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Hide

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Set audible alarm when an IP address comes online

Terminal - Set audible alarm when an IP address comes online
ping -i 60 -a IP_address
2009-03-04 06:21:22
User: haivu
Functions: ping
97
Set audible alarm when an IP address comes online

Waiting for your server to finish rebooting? Issue the command above and you will hear a beep when it comes online. The -i 60 flag tells ping to wait for 60 seconds between ping, putting less strain on your system. Vary it to your need. The -a flag tells ping to include an audible bell in the output when a package is received (that is, when your server comes online).

Alternatives

There are 2 alternatives - vote for the best!

Terminal - Alternatives
until ping -c1 ADDRESS;do true;done;zenity --warning --text "ADDRESS is back"
2011-09-26 18:51:38
User: marcusrp
Functions: ping
Tags: Network zenity
5

I'd rather this one on Gnome, as I'm used to be listening some music while working. I've even created a bash function which receives ADDRESS as parameter.

Know a better way?

If you can do better, submit your command here.

What others think

OSX:

ping -i 60 -A IP

Instead of a bell you can have OSX tell you (this one will check every 30 seconds for 5 minutes)

ping -i 30 -c 10 IP && say -v vicki 'Server is back online'
Comment by vaporub 268 weeks ago

Pinging your system isn't putting any "strain" on it at all. 'ping -f' that sucker, and the only "strain" you're putting anywhere is your network.

Comment by atoponce 268 weeks ago

@vaporub

that will say 'Server is back online' no matter what, regardless of whether or not the ping actually works, and after all pings are done. You are essentially doing:

sleep 300; say -v vicki 'Server is back online'

albeit with ping working in the mean time.

I think you may have missed the concept.

Comment by sudopeople 268 weeks ago

@sudopeople

No, from the man page:

> If ping does not receive any reply packets at all it will exit with

> code 1. If a packet count and deadline are both specified, and fewer

> than count packets are received by the time the deadline has arrived,

> it will also exit with code 1. On other error it exits with code 2.

> Otherwise it exits with code 0. This makes it possible to use the exit

> code to see if a host is alive or not.

Only problem is it will always wait the whole 5 minutes before telling you.

Comment by porges 267 weeks and 6 days ago

Remember about "visual bell" (http://www.faqs.org/docs/Linux-mini/Visual-Bell.html). If you use "visual bell" in your xterm, try:

xset b; ping -a IP; xset -b

turn off "visual bell" before ping, and turn it on after ping.

Comment by unixmonkey2039 267 weeks and 6 days ago

@vaporub: good point, it still misses the mark though. Like you said, it will wait 5 min before telling you if it is up. It would work like this:

sleep 300; ping -c1 IP && say "server is up"

this is a better solution:

while true; do [ "$(ping -c1W1w1 server-or-ip.com | awk '/received/ {print $4}')" = 1 ] && say -v vicky "Server is back online" || echo; sleep 1; done

It would be annoying as hell, but you'd know it was up.

More info: http://www.commandlinefu.com/commands/view/1815/beep-when-a-server-goes-offline

Comment by sudopeople 264 weeks and 1 day ago

The ping command with -o option will exit successfully after receiving one reply packet (at least on Mac OS X):

ping -o $ip && say "Server is back online"

Comment by jh12z 4 weeks ago

Your point of view

You must be signed in to comment.

Related sites and podcasts