April 2009
The Archives
-
04.30.09Changing your login shellYes, I have to admit this is the first thing I do on my account after installing FreeBSD :). This example however, comes from a Linux box (you may notice it due to the default installation paths for the shells). $ chsh -l /bin/ash /bin/bash /bin/csh /bin/tcsh The command above lists the available shells. (I have omitted some of the entries to shorten the list). $ chsh -s /bin/bash The next time you log in, your shell will be bash. Enjoy!
-
04.28.09A cron exceptionSome time ago a workmate asked me why the next cron line didn't work: 0 0 1 * 1 script The script runs every monday at 00:00 and not only the mondays 1th, which should be the expected behavior. That is because of a cron exception. A job is executed when all the time/date specification fields match the current time and date, but if both the day of month and the day of week are restricted (not "*"), then either the day of month or the day of week field must match the current day (even though the other does not).
-
04.26.09Command line Russian roulette$ [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo Click Please notice that this is a fun command before copying and pasting. Via | xeoncross tweet.
-
04.24.09Retrieving files from a URL (the BSD way)$fetch URL This ancient command (it appeared first in FreeBSD 2.1.5) retrieves files from URLs. It is simple and efficient. All its features are encapsulated in the libfetch library which can be accesed from a C program using a predefined API (man 3 fetch). Example: $fetch ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/ISO-IMAGES/7.1/7.1-RELEASE-amd64-bootonly.iso
-
04.22.09Need to know your public IP?Some times you may need to know your public IP address. With this simple command you can find it out: $ curl -s http://checkip.dyndns.org/ | egrep -o "[0-9.]+" There are some other sites where we can discover it like whatismyip or whatismyipaddress, but the user-agent needs to be spoofed beacuse they ban curl, so the solution is using the -A option: $ curl -A "Mozilla/4.0" -s http://whatismyip.com With the above command you will get the entire page bypassing the ban. But as the HTML of this pages is more complex and we do not want to fool them spoofing the user agent, we prefer ...
-
04.20.09Monitoring HTTP requests from the command lineSome days ago Javisantana sent me a tweet with a link to a one-liner HTTP requests monitor. It goes as follows with some ouput added: $ sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E "Host\: .*|GET \/.*" Password: tcpdump: listening on en1, link-type EN10MB (Ethernet), capture size 65535 bytes GET / HTTP/1.1 Host: commandliners.com GET / HTTP/1.1 Host: google.com GET / HTTP/1.1 Host: www.google.com GET / HTTP/1.1 Host: www.google.es GET /intl/en_com/images/logo_plain.png HTTP/1.1 Host: www.google.es [...] Replace en1 with your network interface's name. Usually enX in BSD-like OSes and ethX in Linux. You can create an alias named httpdump and add it to ~/.bash_profile: alias httpdump='sudo tcpdump -i en1 -n -s 0 -w ...
-
04.19.09iostat (BSD)iostat shows I/O statistics. The example below shows statistics of the copying process from an USB music player to my laptop's hard drive. It shows KB per transfer, transfers per second and MB per second, for each device specified in the first row in the statistics report). The last three columns show CPU statistics. You can avoid them with the -d flag. iostat -w 1 tty ad0 da0 ...
-
04.17.09Showing a computer’s open ports$ netstat -an | grep -i listen Shows the open ports on all the IPs of the computer the command is run on.
-
04.13.09OpenBSD’s pf null pointer dereferenceWe have talked quite a few times about pf, OpenBSD's Packet Filter (firewall). Well, a bug has been discovered which may trigger a kernel panic. There exists a solution, be sure to patch your boxes asap. Notice that the 'editing' solution works on all platforms and versions (at least from 4.2 upwards and probably on older ones).
-
04.12.09Extracting an rpm package without installing it$ rpm2cpio myrpmfile.rpm | cpio -idmv Extracts an rpm package in the current directory without installing it. It is very useful when you only want to see its contents.