Click to See Complete Forum and Search --> : What tool to use?


stiles
05-13-2002, 11:40 PM
I'm stuck. Ok here is what I have so far


cat /etc/mtab | awk '{print $2}' > /tmp/inst_$$


which gives the output of:

/
/proc
/dev
/mnt/.init.d
/boot
/var
/usr
/u01
/home
/u02
/u03
/u04
/dev/pts
/dev/shm
/tmp
/var/tmp


Ok now I want to filter inst_$$ to not include any line anchored to the left with:

/dev
/proc
/mnt
/tmp

any ideas? Once I get thoes lines yanked out I should be good.

l01yuk
05-14-2002, 02:53 AM
You could use sed, grep -v, or you could expand your awk to not print the lines you don't want using something like:
awk '{if(! $2 ~ /\/dev\// && <add the rest...>
{
print $2
}}'

grep is probably the easy way.

stiles
05-14-2002, 01:43 PM
Damn you make me wish I knew awk. Thanks for reminding me of grep -v, I must have had a brainfart. Here is my ugly solution (too bad -E does not work with -v, so it's ugly loop time):


#/bin/bash

#------------------------------------------------------------------------------

O_NAME=oracle.install # Name of file created

#------------------------------------------------------------------------------

O_PATH=/var/log # Path where file is created

#------------------------------------------------------------------------------

EXCLUDE="/dev /proc /mnt /tmp" # Filesystems to exclude

#------------------------------------------------------------------------------

INSTALL_C=/home/stile/Disk1/runInstaller # Install command

#------------------------------------------------------------------------------

IUSER=oracle # user to run Install command
# as
#------------------------------------------------------------------------------

PINSTALL_C= # post install command

#------------------------------------------------------------------------------

PUSER=root # user to run post install
# command as
#------------------------------------------------------------------------------
# count the number of filesystems to exclude
EX_NUM=$(echo "$EXCLUDE" | wc -w)

cat /etc/mtab | awk '{print $2}' > /tmp/inst_$$

INC=1

# Ugly loop, should use awk to NOT print
# the filesystems I don't need
while [ $EX_NUM -ge 1 ] ; do
FS=$(echo $EXCLUDE | cut -d " " -f "$INC")
grep -v "$FS" /tmp/inst_$$ > /tmp/inst_$$_tmp
mv /tmp/inst_$$_tmp /tmp/inst_$$
INC=$(echo ${INC}+1 | bc)
EX_NUM=$(echo ${EX_NUM}-1 | bc)
done

find $(cat /tmp/inst_$$) -mount > /tmp/one 2> /dev/null

/bin/bash
# install command
# su -c "$INSTALL_C" $IUSER

find $(cat /tmp/inst_$$) -mount > /tmp/two 2> /dev/null

diff /tmp/one /tmp/two > ${O_PATH}/${O_NAME}

rm /tmp/one
rm /tmp/two
rm /tmp/inst_$$

# post install command
# su -c "$PINSTALL_C" $PUSER

exit 0

YaRness
05-14-2002, 02:05 PM
yikes. all that just to do what you describe, or does it do something else in addition?

this, i THINK, will remove anything startin with /dev and the others, including "/dev" alone

perl -p -e "split; print $_(1) if not $_(1) =~ !^/(dev|proc|mnt|tmp)$!" file.name > output.name

but i don't have aperl interpreter installed, and haven't play with it in months, so i might be totally off. but it's probably pretty close. probably.

stiles
05-14-2002, 03:27 PM
Originally posted by YaRness:
<STRONG>yikes. all that just to do what you describe, or does it do something else in addition?</STRONG>

It does a little bit more, but not much. Getting awk to not print lines the excluded filesystems, or something like your perl string would save about 9 lines and a few I/O's (well at least all the I/O's are in memory).



perl -p -e "split; print $_(1) if not $_(1) =~ !^/(dev|proc|mnt|tmp)$!" file.name &gt; output.name

I so don't know perl, but it is choking around the carrot ( ^ ).

su: ^: bad word specifier

YaRness
05-14-2002, 04:06 PM
dunno, though one thing i know i missed, the regular expression should be

m!^/(dev|proc|mnt|tmp)!

(added the "m" and removed the "$")

[ 14 May 2002: Message edited by: YaRness ]

YaRness
05-14-2002, 04:27 PM
well, i can't get it to work either. between the shell interpreting things before perl even sees it and me being at work i just ain't gonna figure it out right now.

stiles
05-14-2002, 04:44 PM
No problem

l01yuk
05-15-2002, 08:21 AM
I expected you do do somehing like

cat /etc/mtab |
awk '{print $2}' |
grep -v "/dev/" |
grep -v "/proc" |
grep ... &gt; /tmp/inst_$$

which is better to look at.

Style-wise I always try and put these on different lines as above to make it readable.

stiles
05-15-2002, 03:00 PM
I kinda like the fact that if i add to the var $EXCLUDE the # of interations for the loop change and the new (NFS??) filesystem is removed from the list. Ugly but effective?