Skip to main content

Posts

Showing posts with the label humor

Programatically named variables in bash.

Suppose you wanted to do the following in bash: for label in a b c d e f do variable_${label}=${label} done This has the intended result of setting a series of variables: variable_a variable_b variable_c variable_d variable_e variable_f But if what if you want to dereference them programatically? for label in a b c d e f do echo ${variable_${label}} done is not acceptable bash syntax. But there is a way... We can abuse export and env . We set them with: for label in a b c d e f do export variable_${label}=${label} done We can then programmatically dereference the variables by searching for them in the output of env and using awk to get their value. for label in a b c d e f do echo "`env | grep variable_${label} | awk -F= '{print $2}'`" done How's that for bash abuse?

Systems Administration Koans [2008]

Some koans... ----------- A sysadmin asked the Master, "What's the best way to install a new system?" The Master answered, "Turn it on." The sysadmin was enlightened. ----------- A sysadmin asked the Master, "What's the root password to this server?" The Master asked, "Do you have access to the console?" The sysadmin replied, "Yes." The Master replied, "The root password is whatever you want it to be." The sysadmin was enlightened. ----------- An sysadmin seeks approval from the Master: "Master, I have designed and implemented a system with no single points of failure!" The Master answered, "Have you documented it?" "Not yet - I wanted to get it done first." The Master asked, "Give me the name of a team member that can build another one without seeing you or contacting you." "Well, I can't, yet - I just built it." The ...

Linux Live Search...

So... The other day I decided to set up 'locate' to find files in my home network shares, /home/ghostis and /sandbox/ghostis. To do so, I did the following: % mkdir /home/ghostis/Documents/locate Added the an updatedb job to my crontab on my laptop: 15,30 * * * * updatedb --netpaths='/home/ghostis /sandbox/ghostis' --output=/home/ghostis/Documents/locate/locatedb --localpaths=' ' Now I can do faster searches of filenames via: locate -d ~/Documents/locate/locatedb sometextinfilename But, then I thought, "What's the absurd extreme?" Linux Live Search! So I baked a quick bash script: % cat linux_live_search.sh #!/bin/bash clear echo "Please type something. (Escape spaces. Ctrl-C to quit)" echo "------------------------------------------" echo "Query: $WORD" echo "------------------------------------------" while read -s -n1 KEY do clear if [ "$KEY" = "" ] then WORD=`echo "$WOR...