linux commands

Check if an command was successful in bash

When scripting gigantic build scripts with bash, its important that if anything fails you halt the script.

Heres how:

function checkResult() {
	RESULT=$1
	if [ $RESULT -ne 0 ] ; then
		echo
		echo "!!!!!!!!!!!  Build Failed !!!!!!!!!!!!!!!!!"
		echo
		exit $RESULT
	fi
}

You call it like this:

./someCommandOrScript.sh
checkResult $?
  • Share/Bookmark

bash
code
linux commands
sysadmin

Comments (0)

Permalink

iTerm – Upgrade your Terminal

Spending a lot of time in various ssh sessions?

A bit tired of trying to remember which tab is on which server with the default os x terminal ?

So was I. Hunting around, I saw various hacks (e.g. a bash script, or applescript) to achieve this but also an app called iTerm.

Its free and within 30mins I was pretty much back to my previous terminal existence but with the names of my servers and my username in the tabs titles.

Awesome.

Some things I learned:

1) Some of the preferences I had to hunt for:

Not everything is available from iTerm–>Preferences. There are a couple of menu options of interest (this is iTerm 0.9.6).

View–>Show Session Info …

This lets you change the colors and fonts, etc for your terminal window and also update the default.

Bookmarks –> Manage Profiles …

This is where you can set a lot more options about your session, including making the cursor blink (Something for some reason I found essential:)

The reason they are here is because they are associated with bookmarks, a powerful feature that for example allows you to bookmark an ssh session, and have a whole set of preferences associated with that session.

I would like to see them all aggregated under the “Preferences” option though, because as a os x user, thats where I expect to find everything that I can configure (Posted as an feature request.

2) I wanted the title to change whenever I change directory. Simple, just need the following in my ~/.bash_profile (see here for differences between ~/.bashrc:

export PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}: ${PWD/#$HOME/~}\007"'

3) This one is not probably very “good form”, but I really like the icon for the os x terminal window. So simply “Show Package Contents” on the iTerm.app and swap out /Contents/Resources/iTerm.icns with the equivalent in the Terminal application Terminal.icns

4) I also wanted a “close x” icon on each tab, and discovered that this is under Preferences –> Tab –> Use compact tab labels. You want to UN check this.

I now have exactly the same user experience as before with some great bonuses, for example, a cool feature is the “blur” of the transparency behind the window.

  • Share/Bookmark

linux commands
os x
thoughtblog

Comments (0)

Permalink

Login message on unix

I just learned how to put up a messages when you log in to a server…

sudo vi /etc/motd

its not a script so dont need to put “echo” just type what you want.

For a cool ascii text generator, see http://asciiset.com/figletserver.html, I like banner3 as a font.

  • Share/Bookmark

hosting
linux commands

Comments (0)

Permalink

Sweet Search And Highlight Command

Been doing quite a bit of manipulating LaTeX files on the command line recently, and have a very sweet little command for searching for text in multiple files:

grep -r Hoffman */*.tex | less +/Hoffman

Where “Hoffman” is the search term which can of course be any regular expression.

The “less” command has a very convenient argument “+” which allows you to pass a search term in and will automatically highlight it for you.

The -r in grep recurses directories and */*.tex looks for all tex files. the | pipes the result to less.

sweet.

  • Share/Bookmark

bash
latex
linux commands
os x
regex

Comments (0)

Permalink