Posts Tagged ‘bash shell’
* Fall through code to a success…
Posted on December 10th, 2009 by doug. Filed under shell.
I found a piece of code in a nagios alerting script that returns “success” matter what is happening with the jboss application it is checking.
This script had been perpetuated as a service alerting script for years in the environs I work in, edited and passed on as working. It reads:
if [failure code here]; then
# return failure to nagios nrpe daemon
else
# return success to nrpe
fi
The test for a failure failed to match, even when the test was looking for a jboss instance not present on the server. Because the code falls through to success, everything looks just fine, all of the time.
The test for failure being incorrect struck me first when I looked through the script. The more basic flaw in logic hit me after. I think it would be true in an alerting script you would NEVER drop through a loop to a final success. The test would be for success, the fall-through to failure. This would have prevented a false sense of security, and the failure to detect success would have been dealt with immediately.
Something like:
if [success code here]; then
# return success to nagios nrpe daemon
else
# return failure nrpe
fi
Obvious. But an epiphany anyway.
–doug
* stupid shell (and UNIX) tricks
Posted on July 29th, 2008 by doug. Filed under shell.
I love using abobe photoshop C2′s automation – especially when resizing a series of images for the web. I would love to run linux entirely – but linux keeps falling short in graphics programs (yes, I use gimp – sorry, but Photoshop is better) and printer drivers – linux still can’t run my Canon Pixma pro 9000 color printer. That and every corporation I do work for has some required program or access method that seems to insist on only running on windows.
That said, while all operating systems suck to some degree, Windows consistently manages to suck more than most. Cygwin supplements Windows pathetic command line with a bash shell and a lot of UNIX functionality.
When you run adobe batch scripting to resize a series of jpg’s and then save them in a different directory as gif files, it insists on writing “copy” in the file name. photograph1.jpg becomes “photograph1 copy.gif”. To remove the ” copy” string, run:
$ for i in *
> do
> mv "$i" "${i/\ copy.gif}".gif
> done
sed and awk
One of the instructors I had in UNIX system administration courses was… How to put this… One brick short of a wall. He was supposed to include sed and awk UNIX commands i the course, and he glossed over them as “something you would never use, trust me”. A couple of years later, when I needed and had to learn the commands, I thoroughly realized he was very wrong.
I had to rename a series of website pages in a site redesign – including altering the names inside the pages themselves. Here’s how I did it.
Here’s the command that changed one set of links from the old page to the new:
for i in ` grep photographs_5.html * | awk -F : '{ print $1 }'`
do
echo $i
sed 's/photographs_5.html/photographs_001.html/g' < $i > $i.1
mv ${i}.1 ${i}
done
This loops through and finds any files with the string “photographs_5.html”
echos out each file, changes (using the sed command, standard UNIX tool…) from photographs_5.html to photographs_001.html, creating a new file named [file].1,
then replacing the original file by moving (mv) the [file].1 file over on top of the [file].
I love UNIX. Both of these were done on Windows using the bash shell in cygwin. This supplies basic UNIX functionality to Windows, including the bash shell, sed and awk, ssh and rsync (by selecting the package), wget and gpg (extra package selection), and many other functions. The setup program downloads a list, within which you can select additional packages, download and install.
Cygwin at least makes Windows somewhat command line friendly.
—dsm
recent posts
- compacting logs
- I miss my brother…
- home to Boston, daughter in remission
- visually healthy bone marrow…
- matter of the lungs
- Fall through code to a success…
- another tool for SVN – list_repositories.pl
- svnadmin.pl – perl cgi script to manage svn over apache
What I'm Doing...
- waiting for Dell to inform FedEx they've shipped my netbook... 2010-06-07
- sorting out stuff (moving...) 2010-05-25
- downloaded netbook remix (for my Asus) and amd64 (for my 64 bit Intel PC) - desktop for everything else has slowed to 120 kbs... 37 minutes 2010-04-29
- More updates...
Posting tweet...
