Showing posts with label shell script. Show all posts
Showing posts with label shell script. Show all posts

Friday, February 6, 2009

Perl one liners

Join multiple lines:
perl -le 'print join " ", map { chomp; $_ } <>'

Convert unix timestamps:
perl -e 'print scalar localtime (TIMESTAMP)'

Wednesday, December 17, 2008

Quicker cp/mv

Quick way to copy or move a file with less typing:


$ cp test{,.bak}
$ ls
test test.bak


will expand the first non existent parameter (note just the comma in the curly brackets) as the file name test making a copy named test.bak.

Very useful as it allowes you to type less since you have to supply only one argument plus the new file's extension.

Thursday, August 7, 2008

Map device names in Solaris

Sometimes you want to know what devices are being mapped to instance names. To do that I use this script:

#!/usr/bin/ksh

DISKS=$(/usr/bin/ls /dev/dsk/*s2)

for D in ${DISKS}
do
INST=$(/usr/bin/ls -l ${D} | /usr/bin/awk -F" " '{print $NF}' |\
/usr/bin/sed -e 's/\.\.\/\.\.\/devices//g' -e 's/:[a-z]//g')

DEV=$(/usr/bin/grep ${INST} /etc/path_to_inst | /usr/bin/sed 's/\"//g'|\
/usr/bin/awk '{print $3$2}')

echo "${DEV} ${D}"
done
You'll get something like:

sd0 /dev/dsk/c0t0d0s2
sd9 /dev/dsk/c0t10d0s2
sd10 /dev/dsk/c0t11d0s2
sd11 /dev/dsk/c0t12d0s2
sd6 /dev/dsk/c0t6d0s2
sd7 /dev/dsk/c0t8d0s2
sd8 /dev/dsk/c0t9d0s2


Also noted that SarCheck provide a similar tool called dmap, only available for SPARC. This is a script, therefore can be used on x86 and SPARC, as well as machines which are not allowed to have non supported binaries installed on them :)

But if you can install binaries on your systems, then you might want to compile your own from here .