April 2009

The Archives

  • 04.30.09
    Changing your login shell shell | n0str0m0 | (0)
    Yes, 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.09
    A cron exception shell | rafacas | (0)
    Some 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.09
    Command line Russian roulette fun | rafacas | (1)
    $ [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo Click Please notice that this is a fun command before copying and pasting. Via | xeoncross tweet.
  • 04.24.09
    Retrieving files from a URL (the BSD way) shell | n0str0m0 | (3)
    $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.09
    Need to know your public IP? network | rafacas | (0)
    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.09
    Monitoring HTTP requests from the command line network | rafacas | (0)
    Some 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.09
    iostat (BSD) shell | n0str0m0 | (0)
    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.09
    Showing a computer’s open ports cmd, network | rafacas | (0)
    $ netstat -an | grep -i listen Shows the open ports on all the IPs of the computer the command is run on.
  • 04.13.09
    OpenBSD’s pf null pointer dereference network, news, security | pfortuny | (0)
    We 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.09
    Extracting an rpm package without installing it cmd | rafacas | (0)
    $ 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.