Much ado about scripting, Linux & Eclipse: card subject to change


The cow says...

Logging in today, I actually got the BOFH cow to randomly mention division by zero!

To enable this in your ~/.bashrc or /etc/bashrc, install cowsay and fortune, then add this to the end of your script. Note that on some systems you get different fortune options than the ones I've got below.

if [ "$TERM" != "dumb" ]; then
  # define some colour codes to use 
  # eg., 36: cyan, 35: purple, 34: blue, 33: yellow, 32: green, 31: red
  # can also use darker version with 0;36, 0;36, etc.

  echo -e -n $col; # change colour

  # get a fortune and pipe it to cowsay, using the apt cow
  fortune -a 20% riddles 30% literature 10% fortunes 40% excuses     | cowsay -n -f apt.cow; 
  echo -e $norm; # return to normal
If you want to create your own fortunes, have a look in /usr/share/games/fortunes, then create a text file with each line being a unique message. In the example below, I called this file BOFH_excuses.txt, sourced here. Process the file with gawk to change this:
High line impedance.
Someone set us up the bomb.
Power surges on the Underground.
into this:
The BOFH says: High line impedance.
The BOFH says: Someone set us up the bomb.
The BOFH says: Power surges on the Underground.
$ gawk -F: '{ print "The BOFH says: "$1"\n%" }'  BOFH_excuses.txt > excuses; 

Now, each entry in excuses ends with a newline and a "%". Multi-line entries are also separated by "%" - see other files in the /usr/share/games/fortunes folder for examples.

To index your new file so that fortune can use it, you must run it through strfile:

$ strfile excuses excuses.dat

Finally, to test your new fortunes, run this:

$ fortune excuses