[plug] A bit of gross bash code

Brad Campbell brad at seme.com.au
Wed Mar 7 16:03:52 WST 2001


Ok, I'm sure you have had enough of me today, but here is a bit
of bash code I wrote to solve a problem..
Question is, is there an easier way to do this.. or am I on the right
track. I mean, it works, but it's very rough.
As you can see, I'm pretty new to the bash scripting arena, but I can
read man pages :p)


it takes an ls -la /dev

crw--w--w-    1 0        5         29,  28 Feb 23  1999 fbuser4
crw--w--w-    1 0        5         29,  29 Feb 23  1999 fbuser5
crw--w--w-    1 0        5         29,  30 Feb 23  1999 fbuser6
crw--w--w-    1 0        5         29,  31 Feb 23  1999 fbuser7
lrwxrwxrwx    1 0        0              13 Apr 14  2000 fd -> /proc/self/fd
brw-rw----    1 0        25         2,   0 Feb  9  2000 fd0
brw-rw----    1 0        25         2,  84 Feb  9  2000 fd0u1040
brw-rw----    1 0        25         2,  88 Feb  9  2000 fd0u1120
brw-rw----    1 0        25         2,  28 Feb  9  2000 fd0u1440
brw-rw----    1 0        25         2, 124 Feb  9  2000 fd0u1600
 
and generates an : delimited file for me to parse later

c:0:5:29:28:fbuser4
c:0:5:29:29:fbuser5

You get the idea.. it does this for types c,u & b

<-horrible code->

#!/bin/sh
# This creates a list of devices with : delimited fields for easy
# parsing through mknod
# Field 1 - Device Type
# Field 2 - Owner
# Field 3 - Group
# Field 4 - Major Number
# Field 5 - Minor Number
# Field 6 - Name



echo Creating List of Devices..
echo "#" > devs.list
cd disk/dev
for f in `ls`; do
TMP=`ls -la $f | cut -c1`
TMP=$TMP":"`ls -lan $f | cut -c 17-36 | cut -f 1 -d " "`
TMP=$TMP":"`ls -lan $f | cut -c 26-36 | cut -f 1 -d " "`
TMP=$TMP":"`ls -lanG $f | cut -c 17- | \
	cut -f 2-100 -d " " | cut -f 1 -d "," | \
	sed -e "s/\ *//" | cut -f 1 -d " "`
TMP=$TMP":"`ls -lanG $f | cut -c 17- | \
        cut -f 2-100 -d " " | cut -f 2 -d "," | \
        sed -e "s/\ *//" | cut -f 1 -d " "`
TMP=$TMP":"`ls -lanG $f | cut -c 48-`


if [ `echo $TMP | cut -c1` = "b" ]
then
	echo $TMP >> ../../devs.list
fi
if [ `echo $TMP | cut -c1` = "c" ]
then
	echo $TMP >> ../../devs.list
fi
if [ `echo $TMP | cut -c1` = "u" ]
then
	echo $TMP >> ../../devs.list
fi

done;

echo Done..
cd ..
echo Creating list of Links...
ls -la `find . -type l` | cut -c 58- | cut -f 1,3 -d " " > ../links.list

cd ..
echo Done..

<-end horrible code->

-- 
Brad....
                   /"\
Save the Forests   \ /     ASCII RIBBON CAMPAIGN
Burn a Greenie.     X      AGAINST HTML MAIL
                   / \



More information about the plug mailing list