Archive for the ‘shell’ Category

* 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

share: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • Reddit
  • Bloglines
  • email
  • Facebook
  • Faves
  • LinkedIn
  • Mixx
  • Netscape
  • Newsrider
  • Slashdot
  • Technorati
  • TwitThis

Tags: , , .



* eclipsed

Posted on March 29th, 2009 by doug. Filed under Solaris, UNIX & Windows, eclipse, shell.


 

 

eclipse splash

 

I’ve been working with Remote System Explorer (RSE), a terminal and ssh session manager that runs in the Eclipse SDK. This is very cool – the thing is, eclipse runs on Solaris, Linux, Windows, MAC OSX, IBM AIX (of course – IBM created the eclipse framework). It as close to an OS-agnostic framework as anything I’ve ever experienced.

I had primarily intended to use it on windows to add ssh terminal capacity – replacing console2 and cygwin – to connect to UNIX servers. But the interface is so good, I find I’m using it on both UNIX and windows – the konsole terminal is better in some ways at history and at cut-and-paste using mouse buttons directly. So far the context menu from a right-click is the only cut-and-paste that functions within the terminal windows themselves.

On the other hand – in konsole each separate terminal window is a separate authentication – password-response – whereas in eclipse RSE, one authentication can be kept and spawn as many terminal sessions as needed. The organization is better. You can close the terminal sessions down, and leave a connection still intact. Then bring back terminal sessions as needed. That ability alone makes it worth losing the double-click select and middle-button paste from konsole sessions. I’m not yet convinced I can’t find a way to get that working either, that and an unlimited history or at least 10000 lines…

 

eclipse window

 

If I can get that back somehow in the terminal sessions it will be not just slightly better, but a huge amount better than any other session management I’ve used.

Install

You need java. On windows that can be an issue. On UNIX, not so much, pretty much there by default.

Download RSE and eclipse SDK.

Untar or unzip the eclipse package. In windows I unzip to c:\eclipse_3.4.2. In UNIX /usr/local/eclipse.

Unzip the RSE package layered over the eclipse install.

In windows I point a shortcut to c:\eclipse_3.4.2. In UNIX I move /usr/local/eclipse to /usr/local/eclipse_3.4.2, and create a symbolic link /usr/local/eclipse -> /usr/local/eclipse_3.4.2.

Open eclipse. Go to window -> open perspective -> other and open Remote System Explorer.

 

eclipse window

 

Configurations are stored in the workspace folder. Right-click in the left-hand pane and select “New Connection to create connections. Within eclipse you can add software respositories and update and add software from Help -> Software Updates.

 

eclipse window

eclipse window

 

 

— doug

 

share: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • Reddit
  • Bloglines
  • email
  • Facebook
  • Faves
  • LinkedIn
  • Mixx
  • Netscape
  • Newsrider
  • Slashdot
  • Technorati
  • TwitThis

Tags: , , , , .



* TERM=vt220

Posted on August 29th, 2008 by doug. Filed under Uncategorized, shell.


 

console2 with cygwin bash shell and ssh behind it (and a lot of other UNIX commands too, like ls, and find and grep and awk and gpg…) has turned out to be a good solution.

I discovered that cygwin sets the terminal as TERM=cygwin. That plays hell with vi on SUN servers. I found that setting “export TERM=vt220″ in .profile (this is SUN Solaris 10) resolved vi, getting the console2 window to show the display correctly, and letting the arrow keys work again.

A second gotcha – DON’T set ctrl-c as copy in the hot-keys. That ctrl-c you use to break out of errant commands or scripts stops working at all, very disconcerting. Instead map shift-ctrl-c. There’s an alpha feature enabling tranparency – looks cool, but isn’t stable. Ctrl-r (history searching in bash) is mapped to renaming the tabs for console windows – you’ll set that to ctrl-alt-n as below and resolve that.

Here are the settings in console2 I’ve found to come very close to what I use in Konsole in KDE:

  • base underneath is cygwin – therefore need “export TERM=vt220″ in .profile to have vi behave on SUN – run on command line initially to test and to edit .profile…
  • add “c:\cygwin\bin to path in control panel -> system -> advanced -> environmental variables
  • console:
    • shell is c:\cygwin\bin\bash.exe
    • working directory is c:\
    • buffer size Rows is 5000, columns is 0
  • appearance:
    • more – set tabs to always be present (uncheck “hide single tab”)
  • behavior:
    • check copy on select
    • check clear selection on copy
    • select UNIX LF
  • map hotkeys to emulate konsole
    • shift-left for previous window
    • shift-right for next
    • ctrl-alt-n for new windows
    • ctrl-alt-s for rename
    • shift-up arrow for line up
    • shift-arrow down for line down
    • shift-page-up for page up
    • shift-page-down for page down
    • shift-ctrl-c for copy
    • ctrl-v for paste
  • mouse:
    • right button to paste
    • set copy on select
    • left button to select
    • copy/clear selection is “none”
  • tabs:
    • set shell as C:\cygwin\bin\bash.exe
    • working directory is C:\

 

— dsm

 


 

UPDATE 20080904: I installed console2 on all of my windows machines (dual boot, except for work). It worked perfectly – then a co-worker tried it out and had issues. He searched and found that in some instances cygwin’s bash shell refused to complete loading and never returns a command prompt. The solution looks to be a reinstall or upgrade of cygwin, or possibly some difference in the way cygwin was installed.

I laughed and said, “It works for me.”

He said, “You can tell when you work in an IT shop – when something fails for someone, you always get that response – “It works for me.”"

 

Update 20090329 Sunday

export TERM=ansi

I installed eclipse with Remote System Explorer. vt220 caused VI to fail to refresh (at least SUN’s crippled vi version). ansi worked much better within RSE.

— doug

 

share: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • Reddit
  • Bloglines
  • email
  • Facebook
  • Faves
  • LinkedIn
  • Mixx
  • Netscape
  • Newsrider
  • Slashdot
  • Technorati
  • TwitThis

Tags: , .



* 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

share: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • Reddit
  • Bloglines
  • email
  • Facebook
  • Faves
  • LinkedIn
  • Mixx
  • Netscape
  • Newsrider
  • Slashdot
  • Technorati
  • TwitThis

Tags: , , , , .



engineers

recent posts

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...

categories

archives

tag cloud

apache apache2 bash shell browsers comics compile cygwin data databases daughter eclipse economics engineer entropy finances firefox 3 hallucinations Heinlein internet java jboss KDE linux moinmoin monitoring nagios plugins RSE scifi script Solaris structure subversion support svn testing tweet UNIX UNIX & Windows web hosting website websphere windows WordPress writing

admin