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/
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.
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
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:
Super fast way to ftp/telnet/netcat/ssh/ping your loopback address for testing. The default route 0.0.0.0 is simply reduced to 0.
Execute commands serially on a list of hosts. Each ssh connection is made in the background so that if, after five seconds, it hasn't closed, it will be killed and the script will go on to the next system.
Maybe there's an easier way to set a timeout in the ssh options...
This version combines the best of the other suggestions and adds these features:
1. It scans a /16 subnet
2. It is very fast by running the ping commands in the background, running them in parallel.
3. Does not use the "-W" option as that's not available in older ping versions (I needed this for OS X 10.5)
Nasty perl one-liner that provides a sparkline of ping times. If you want a different history than the last 30, just put that value in. It (ab)uses unicode to draw the bars, inspired by https://github.com/joemiller/spark-ping . It's not the most bug-free piece of code, but what it lacks in robustness it makes up for in capability. :)
If anyone has any ideas on how to make it more compact or better, I'd love to hear them.
I included a ping to google in the command just as an example (and burned up 10 chars doing it!). You should use it with: $ ping example.com | $SPARKLINE_PING_COMMAND
A simple way to find all machines on a network subnet is pinging a broadcast address (-b flag). First run ifconfig ifconfig. Then use "Bcast" address and '-b' flag in ping
This command uses ping to get the routers' IP addresses to the destination host as traceroute does. If you know what I mean..
export THISOS="`uname -s`"
if [ "$THISOS" = "SunOS" ]
then
export THISRELEASE="`uname -r`"
ping1() { ping -s $1 56 1 | egrep "^64"; }
elif [ "$THISOS" = "AIX" ]
then
export THISRELEASE="`uname -v`.`uname -r`"
ping1() { ping -w ${2:-1} $1 56 1 | egrep "^64"; }
elif [ "$THISOS" = "Linux" ]
then
export THISRELEASE="`uname -r`"
ping1() { ping -c 1 -w ${2:-1} $1 | egrep "^64"; }
fi
I have used single packet, and in a silent mode with no display of ping stats. This is with color and UI improvement to the http://www.commandlinefu.com/commands/view/10220/check-if-a-machine-is-online. It is as per the enhancements suggested.
PING
parameters
c 1 limits to 1 pinging attempt
q makes the command quiet (or silent mode)
/dev/null 2>&1 is to remove the display
&& echo ONLINE is executed if previous command is successful (return value 0)
|| echo OFFLINE is executed otherwise (return value of 1 if unreachable or 2 if you're offline yourself).
I personally use this command as an alias with a predefined machine name but there are at least 2 improvements that may be done.
Asking for the machine name or IP
Escaping the output so that it displays ONLINE in green and OFFLINE in red (for instance).
Cleaner with a mailto assignment in crontab (if the command fails you get an email):
MAILTO=admin@example.com
10,30,50 * * * * ping -q -c1 -w3 192.168.0.14 >/dev/null
Every 20 minutes test if host with IP 192.168.0.14 is 'dead' or not reachable.
The line should be put in your crontab file.
Every 20 minutes ping host with IP address 192.168.0.14. If it's not 'alive' or not reachable, then display something eye-catching (here xeyes) on the desktop.
Hint for newbies: edit crontab with
crontab -e
Quick and dirty one-liner to get the average ping(1) time from a server.
Change the IP address from 127.0.0.1 to the target machines ip address. Even if the target has ICMP (ping) blocked, it will show you what ports are open on the target. Very handy for situations where you know the target is up and online but wont respond to pings.
This command are using by me for checking connection with Internet.
If you're very busy and don't want to wait for a ping response, use it.
This command will be waiting for a successful ping response, to play a sound file to warn you that the target host is available.
This is like ping -a, but it does the opposite. It alerts you if the network is down, not up. Note that the beep will be from the speaker on the server, not from your terminal.
Once a second, this script checks if the Internet is accessible and beeps if it is not. I define the Net as being "UP", if I can ping Google's public DNS server (8.8.8.8), but of course you could pick a different static IP address. I redirect the beep to /dev/console so that I can run this in the background from /etc/rc.local. Of course, doing that requires that the script is run by a UID or GID that has write permissions to /dev/console (usually only root).
Question: I am not sure if the -W1 flag works under BSD. I have only tested this under GNU/Linux using ping from iputils. If anybody knows how portable -W is, please post a comment.
For some reason the 2&>1 does not work for me, but the shorter stdout/stderr redirection >& works perfectly (Ubuntu 10.04).
It really disables all ICMP responses not only the ping one.
If you want to enable it you can use:
sudo -s "echo 0 > /proc/sys/net/ipv4/icmp_echo_ignore_all"