bob's tech ramblings

where i ramble about technical things

Entries tagged "bash".

1st October 2006

For a while now ive been using aliases to connect to machines. I alias a $hostname to xterm -T $hostname -e ssh $hostname &. This means each connection gets a new fresh xterm. Of course doing an alias command for each host woudl be tedious so i have some magic in bash startup stuff.

bob@betty:~ >cat .bashrc 
[ -f ~/.bash_aliases ] && . ~/.bash_aliases
PS1="\u@\h:\w >"
PATH=$PATH:/usr/sbin:/usr/local/sbin:/sbin
bob@betty:~ >cat .bash_aliases 
for MACHINE in `cat ~/.machines`
do
alias $MACHINE="xterm -T $MACHINE -e ssh $MACHINE &"
done

Where .machines is a list of machines one per line

Recently I have been connecting to machines which arnt in this list with ssh directly. This has the disadvantage that they dont get their own xterm and I have to start another xterm manually if I need another one. So I started to looking into aliasing ssh to the same thing. However, aliases arnt clever enough for this you need to use functions instead.

So I wrote a function to do what i wanted.

function ssh {
xterm -T $1 -e ssh $1 &
}

It then occured to me since this is just programming perhaps I can expand this to check to see if host is mentioned in .machines and if it isnt add it. So I wrote a function

function testmachine {
machine=`grep $1 ~/.machines`
if [ "x$machine" = "x" ]
then
        echo "not in ~/.machines adding"
        echo $1 >> ~/.machines
        source ~/.bash_aliases
fi
}

As you can see it also then sources ~/.bash_aliases this makes sure that the current shell gets the new alias. I then added more to the ssh fucntion

function ssh {
xterm -T $1 -e ssh $1 &
testmachine $1
}

I then told my .bashrc to source a new file called .bash_functions which contains the two fucntions from above. And everything is now good.

Tags: bash, hints, ssh, tricks.

5th January 2008

The other day Deanand I were seeing if a HP PA-RISC workstation Dean had got off ebay worked. We managed to get it powered on going to serial console. Then jury rigged a cd drive to try an install of HP-UX.

It would seem the install cd Dean had didnt like doing the install over serial so we had to connect up a monitor and keyboard. Thankfully IBM use the same funny DVI connector for their servers.

We proceeded with the install, which was a new and exciting experience for me. We got a failure when it tried to install stuff like mozilla and GTK from the second and third install discs. However the main OS install seemed to be fine so we carried on. Even the big FAILURE printed using banner didnt put us off.

So after several reboots we got to a stage where we could login. So we did. Then we found there was no bash and our sh skills are a little rusty. Not having tab completion is pain. Time for some software install using swinstall. We hit a problem here. It would seem that swinstall is network aware and wishes to resolve the name of your host before it will install stuff. We then spent 30 minutes scracthing our heads until we realised that while there were 6 or so nsswitch files none of them was actually nsswitch.conf. So the OS really had no idea what was going on.

After all that we managed to get bash installed from a Porting And Archive Centre for HP-UX package. The relief was great as we could finally tab complete

Tags: bash, hpux, install.

6th January 2008

In the pub the other day for the London.pm Social Smylers brought up the stuff he uses to make hostnames a bash command. He also found the time to generate some hate.

I do this another way as I have previoulsy blogged. Dominic Mitchell at the time pointed out that my scripting sucks. In fact my current version takes his suggestions on board.

Tags: bash, london.pm, pub, ssh.

7th January 2008