Impress your co-workers with wheezak

When you don’t know what else to do, resort to the bs language of wheezak. Note, install wheezak on your servers when no one is looking:

/home/root> ln -s /usr/bin/od /usr/local/bin/wheezak

Now just type a bit and act alternatively perplexed and satisfied as you communicate real time with the wheezak engine:

/home/root> wheezak
lsa
0000000 066163 060412
lsl
0000004 066163 066012
wheezak
0000010 073550 062545 075141 065412
smack
0000020 071555 060543 065412
dogta ( dsa )
0000026 062157 063564 060440 024040 062163 060440 024412
wheezak
0000044 073550 062545 075141 065412
smack
0000054 071555 060543 065412
^C

Convenient debugging with exit, unformatted data read

The following script is an example of two things. The first is how to preset a trap to do all of your cleanup, then you can exit anywhere in your script and it will still remove your temporary files. The other is just a silly idea using grep to handle unformatted data after the exit.

Script started on Fri 23 Sep 2011 02:46:04 PM CDT
 #  cat traptest 
#!/bin/bash
trap "rm $$.*" INT TERM EXIT #
grep -v "#" $0
ls > $$.ls #
exit # Everything after this will not be executed,
# but the trap above will always clean up your temp
# files, so you could use exit as a debugging tool

You can type all sorts of stuff here and it
will be displayed, but need not be echoed.
 #  ./traptest 

You can type all sorts of stuff here and it
will be displayed, but need not be echoed.
 #  exit 
exit
Script done on Fri 23 Sep 2011 02:46:14 PM CDT
  

Transforming File Names

The following small script simply does a file name replacement. One place where it is useful is when I have a bunch of log files with fully qualified names but then change the server hostname to not be fully qualified and I want all stardard historical information.

#!/bin/ksh

## usage: transtr "Initial String" "Final String" [run]
##
## This command simply transforms a string with the
## default sed substitution.  You must include
## 'run' in the third field for it to execute, otherwise it
## simply returns the two strings.  You could actually
## not specify run and pipe the two fields into another
## command if necessary.
##

if [[ $1 == "" ]]
   then
      grep "^##" $0 | cut -c 3-
      exit
fi

while read STRING
   do
      NEW=`echo $STRING | sed "s/$1/$2/g"`
      echo $STRING $NEW
      if [[ $3 == "run" ]]
	then
       	   mv $STRING $NEW
      fi
   done

Script started on Tue 02 Aug 2011 10:33:28 AM CDT
 #  ls 
20110707_05_french-roast.deadlycoffee.com_aixbase.sbstats
20110708_05_french-roast.deadlycoffee.com_aixbase.sbstats
20110709_05_french-roast.deadlycoffee.com_aixbase.sbstats
20110710_05_french-roast.deadlycoffee.com_aixbase.sbstats
20110711_05_french-roast.deadlycoffee.com_aixbase.sbstats
20110712_05_french-roast.deadlycoffee.com_aixbase.sbstats
 #  ls | transtr ".deadlycoffee.com" "" 
20110707_05_french-roast.deadlycoffee.com_aixbase.sbstats 
	 20110707_05_french-roast_aixbase.sbstats
20110708_05_french-roast.deadlycoffee.com_aixbase.sbstats 
	 20110708_05_french-roast_aixbase.sbstats
20110709_05_french-roast.deadlycoffee.com_aixbase.sbstats 
	 20110709_05_french-roast_aixbase.sbstats
20110710_05_french-roast.deadlycoffee.com_aixbase.sbstats 
	 20110710_05_french-roast_aixbase.sbstats
20110711_05_french-roast.deadlycoffee.com_aixbase.sbstats 
	 20110711_05_french-roast_aixbase.sbstats
20110712_05_french-roast.deadlycoffee.com_aixbase.sbstats 
	 20110712_05_french-roast_aixbase.sbstats
 #  ls | transtr ".deadlycoffee.com" "" run 
20110707_05_french-roast.deadlycoffee.com_aixbase.sbstats  
    20110707_05_french-roast_aixbase.sbstats
20110708_05_french-roast.deadlycoffee.com_aixbase.sbstats  
    20110708_05_french-roast_aixbase.sbstats
20110709_05_french-roast.deadlycoffee.com_aixbase.sbstats  
    20110709_05_french-roast_aixbase.sbstats
20110710_05_french-roast.deadlycoffee.com_aixbase.sbstats  
    20110710_05_french-roast_aixbase.sbstats
20110711_05_french-roast.deadlycoffee.com_aixbase.sbstats  
    20110711_05_french-roast_aixbase.sbstats
20110712_05_french-roast.deadlycoffee.com_aixbase.sbstats  
    20110712_05_french-roast_aixbase.sbstats
 #  ls | transtr ".deadlycoffee.com" "" run 

 #  ls 
20110707_05_french-roast_aixbase.sbstats
20110708_05_french-roast_aixbase.sbstats
20110709_05_french-roast_aixbase.sbstats
20110710_05_french-roast_aixbase.sbstats
20110711_05_french-roast_aixbase.sbstats
20110712_05_french-roast_aixbase.sbstats
20110713_05_french-roast_aixbase.sbstats
20110714_05_french-roast_aixbase.sbstats
20110715_05_french-roast_aixbase.sbstats
 #  exit 
exit

Script done on Tue 02 Aug 2011 10:34:13 AM CDT
  

Wrapping text around a string with sed & functionality

Need to use sed to do a string replacement.

This:


# Comments until end of line


Should be:


<span class=comment>#Comments until end of line</span>


This can be accomplished with sed by using the ‘&’ operator which pastes in the match space.

 

Script started on Mon 01 Aug 2011 04:47:45 PM CDT

deadlycoffee:/tmp #  sed 's/^#.*.$/(&)' test | sed 's/^#$/(&)/' 
(#)
(#)
(#)
this is not a comment
this isn't either
(## This is)
(# So is this.)
deadlycoffee:/tmp #  exit 
exit

Script done on Mon 01 Aug 2011 04:48:52 PM CDT

 

In the above example, I do a much simpler replacement, but it is the same idea.

Reporting Packages

Is it possible for a reporting solution to both ‘look’ sufficiently effective to be purchased by the average IT department and ‘be’ sufficiently effective to accomplish anything of value? This is the real question and it seems sad that solutions may have to either pick one side or the other.