Nicolás Brailovsky


A modern blog

Archive for the ‘Console’ Category

Oh my god

author Posted by: nico on date Jul 29th, 2010 | filed Filed under: Console
An old good Unix console joke goes like this:

% ar m God
ar: God does not exist

Obviously thats a very old and used joke, nowdays we’re much more advanced than that:

$ ar m God
$ ar: creating God

Elvis is alive!

author Posted by: nico on date Jul 6th, 2010 | filed Filed under: Console, Linux

Unix trivia day: in the olden days of the 90’s there were a lot of Unix boxes out there named “elvis”. Nowdays it’s not uncommon to find one, either. Have you ever wondered why are there so many boxes called elvis?

This is related to Solaris’ ping command. When you ping $HOST it prints “$HOST is alive” (if it’s responding the pings), thus elvis is alive!

sed magic: a simple guide

author Posted by: nico on date Sep 24th, 2009 | filed Filed under: Console, Programming
The other day I had to create one of those “enum to string” functions. They really suck, always getting out of sync, so I made a script to auto-update the header file containing this function… just add a target to the makefile and you’re done! 11Sed

Anyway, this is the part of the script I came up with to get the enum elements:


cat enum_definition.h | sed -n ‘/enum OID/,/\}\;/ s/\(.*\)/\1/p’

Nice voodoo, isn’t it? How the hell are you supposed to understand that? Well, you’re not, sed is write-only-code, but you can try reading http://www.grymoire.com/Unix/Sed.html#toc-uh-25, a great sed introduction.

Have fun!

Console foo: Scheduling commands

author Posted by: nico on date Sep 15th, 2009 | filed Filed under: Console
You can easily schedule a command using “at”, which recognizes a nicely formatted date string. For example:

  1. $ at today 3:00 AM

This will open a prompt. So, for example:

  1. $ at today 3:30 PM
  2. > wget foobar.com/a_huge_file
  3. > C-D

Will schedule a download of a huge file, today at 3:00 AM. Nice, isn’t it?
To check the whole list of accepted formats check the man for at.

At-at

One last note: at will “remember” the current environment variables, so PWD, USER, OLD_DIR and all that will be the same. This means if you schedule a command with a relative path it’ll still work!

mocp rand

author Posted by: nico on date Jul 23rd, 2009 | filed Filed under: Console, Programming
music-score I’m quite sure everyone reading this must have a respectable, if not massive, music collection. In this days and age is difficult finding someone who doesn’t. It’s also difficult to choose one, and only one, disk to listen at any given moment. Until we’re upgraded to support concurrent music listening we’re better of with a random disk selector, which is exactly what this little script does:
  1. #!/bin/bash
  2.  
  3. SEARCH_DIR=‘/home/nico/Música’
  4. START_RANDOM=1
  5. RAND_MAX=32767
  6.  
  7. while (( 1 )); do
  8. NUM_DISCS=$(find $SEARCH_DIR -type d|wc -l)
  9. RAND=$(($NUM_DISCS * $RANDOM / $RAND_MAX))
  10. RAND_DISC=$(find $SEARCH_DIR -type d | head -n $RAND | tail -n 1)
  11.  
  12. # Wake up moc
  13. mocp -FS 2>/dev/null >/dev/null &
  14. mocp -pca "$RAND_DISC" &
  15. echo "Playing $RAND_DISC"
  16.  
  17. # Start from a random file?
  18. if (( $START_RANDOM )); then
  19. mocp –on shuffle &
  20. mocp -f &
  21. mocp –off shuffle &
  22. fi
  23.  
  24. read
  25. done
Of course, it requires mocp, my favorite music (on console) player. And obviously, you’ll have to configure SEARCH_DIR but I’m sure some bash hacking is not that hard.
Beware though, using this + cron may have the undesired effect of awakening to the pleasant music of Cannibal Corpse.
0601_ozzy_osbourne_c