Linux Blog

BSOD Humor

Filed under: General Linux — TheLinuxBlog.com at 11:36 am on Monday, July 7, 2008

Had a great time yesterday, a friend of mine came over. After dinner he was looking at some t-shirts since an advertisement had distracted him from his initial IMDB search. Some how this made him decide he wanted to make my desktop background a BSOD. I’m a big fan of the BSOD screensaver, and think its funny, whats even funnier is he figured out how to change my background on KDE (although it’s not that hard)

I saw the BSOD with the horrible background just staring at me. It was the classic, “there was an error processing your error”. I never see such things on my Linux box, I’m more used to failed reboots from failing to compile a kernel feature, so jokingly I click on the message box while laughing:

“Why won’t this go away”

Some people find humor in other peoples agony, this is why the TV series (and movies) Jackass do so well. I find humor in BSOD’s and hope that other Linux admin’s do to. But having a BSOD on your Linux box that’s not a screen saver is quite annoying, its like “Gates strikes back”

Here’s a poster I found amusing the other day:

Credit http://www.joyoftech.com/Billy Gates



Decision making in Bash If / Then / Else statements and Cases

Filed under: Shell Script Sundays — TheLinuxBlog.com at 3:44 pm on Sunday, August 5, 2007

There comes a time in every shell script where a decision has to be made.

To make a decision in bash the following if then else syntax can be used:

if [ condition ]
then

statements

[ elif [ condition ]

then

statements ]

[ else

statements ]

fi

Anything in non bold [ brackets ] is optional, and they should not be typed but the bold in them is required. Anything in bold must be typed. Statements are generally other commands or flow control statements.

To give an example of how to use bash if then else statements in the real world take the following scenario:

A system administrator has a strict habit of firing people that have too many .png files. He checks the systems regularly and makes sure that nobody has too many. The following script will display a message depending on the number of .png’s that are in the directory.

#!/bin/bash
gif_count=$(ls | grep .png | wc -l)
echo “Number of PNG’s: $gif_count”
if [ $gif_count -lt 10 ]
then
echo “He will be happy, you have less than 10 files”
elif [ $gif_count -gt 10 ] && [ $gif_count -lt 20 ]
then
echo “Consider deleting some files”
else
echo “you have too many files, DELETE SOME BEFORE HE FINDS OUT!”;
fi

Using Cases.

Cases are similar to if statements in that they match a expression and perform a task if the pattern is matched.

bash case syntax:

case expression in

pattern1 ) statements ;;

pattern2 ) statements ;;

esac

This is fairly simple and some people find this easier than doing if statements for simple logic. Take the following real world example:

The system administrator has recently gone on a bigger power trip than before. Since people got wise about using png’s and started saving images in other file formats he is now monitoring png’s gif’s and jpg’s. To combat the problem, you can use a case to count how many files you have of each type. (This is intended as an example, there are many ways to accomplish this task, this is just to demonstrate how cases work)

#!/bin/bash
#set all variables to 0
png=0
gif=0
jpg=0

# start loop
for wc in $(ls); do

case “$wc” in
*png ) let png=$png+1 ;;
*gif ) let gif=$gif+1 ;;
*jpg ) let jpg=$jpg+1 ;;
esac

# end loop
done

echo “Png’s $png”;
echo “gif’s $gif”;
echo “jpg’s $jpg”;

There you have it, two ways to make basic decisions in bash. Just figure out what you want to do then use an if then else, or a case statement to do the logic. I myself prefer if statements over cases as they make more sense to me and I find it easier to perform logic within ifs.

Programs used in this post
ls, echo, grep, wc