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
- 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
- testing Crosspress (plugin)…
- subversion compile and install as non-privileged user…
What I'm Doing...
- flying back to Boston tomorrow, and watching my daughter come off a ventilator and breathe on her own... 2 weeks ago
- writing a startup and shutdown sc ript for all of jboss-land 2009-08-25
- finished and deployed svnadmin.pl cgi, documented it and checked into subversion... next is more log4j edits, and deploy jsvn (java svn) 2009-05-08
- More updates...
Posting tweet...
