One of the main rules when working on production servers is to keep trace of your actions. That is, so called, “cover your ass” policy. :) As most of my colleagues in IBM are using Windows on their workstations (strange isn’t it?!) they are using putty which provides logging options for their SSH sessions. But I am using Linux and OpenSSH client does not provide this luxury so I had to create this short script to save my SSH logs. It will start SSH client with all the parameters you pass over the command line but at the same time it will also start script command and log everything in right log file. Very neat. :)
#!/bin/sh
USER=$(whoami)
LOG_FOLDER=/log/ssh/${USER}
DATE=$(date +’%Y-%m-%d_%H:%M’)
case “$1″ in
’hostA’)
HOST=”admin@hostA.example.com”
;;
’hostB’)
HOST=”admin@hostB.example.com”
;;
*)
HOST=$1
;;
esac
LOG_FILE=${LOG_FOLDER}/${HOST}_${DATE}.log
[ ! -d ${LOG_FOLDER} ] && mkdir -p ${LOG_FOLDER}
shift
script -c “ssh ${HOST} $*” ${LOG_FILE}
Hi Miljan,
I was reading your note about “How to Change Default System Dump Device in AIX”. You can check out the dumpcheck command (full path is /usr/lib/ras/dumpcheck). Hint: dumpcheck -p ;)
Regards,
Levente
Hey Levente,
Nice to see you here. :) dumpcheck looks very useful, I will use it next time for sure. Thanx for the tip. ;)
BTW, how is it back in the homeland? :)
it’s sweeeeeeeeeeeet :)
Hehehehe… thought so. :) But I bet you miss us a lot. :P
nice one! thank you! :)
Well, this is a bit late, but I have read this entry recently.
First, there is PuTTY for Linux as well if you need (more or less) the same. It works fine, but you don’t have the ‘window context menu’ (no Duplicate Session or Change Settings etc.) Second, the apostrophes used in the above code are not suitable for direct copy paste into the shell (they are not ‘typewriter apostrophes’, rather ‘acute accents’.)
LGee
Hello LGee, thanx for dropping by. :)
Yes, there is PuTTY for Linux, but why would you use it when you have “normal” ssh client from the console? I don’t like using additional tools unless it is really necessary.
And you are also right about the quotes and apostrophes, it is the problem of WordPress software which is used on this blog. Unfortunately, there is no workaround for this.
thanks for the information but Linux is very good..
There is an alternative: just use tee command.
example:
ssh user@host | tee -a my-nice.log
that’s it.
Awesome! This last command save me lots of time.. and is very useful…
Regards and Thank You to Yury.