Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problems with substitution 1

Status
Not open for further replies.

valle70

IS-IT--Management
Jun 11, 2004
6
DK
Hi
I have som problems with substitution in a script I am putting together and I hope someone can help me.
My problem is with the variable $EXCLUDES in the variable CMD1.

The script is showen below.
------------- script1 ---------------
#!/usr/bin/ksh
LOG=/home/user1/cleanup.log
CONF=/home/user1/cleanup.conf
EXCLUDES=`sed 's/,/\|\/sbin\/grep -v/g' $CONF`
CMD1=`grep /var/opt/ignite/clients $LOG $EXCLUDES`
for i in $CMD1;do
server=`echo $i |awk -F: '{print $1}'`
echo $server
done
------------- script1 ---------------

The contens of cleanup.log is showen below
---------- cat cleanup.log -----------
node1:/var/opt/ignite/clients
node4:/var/opt/ignite/clients
---------- cat cleanup.log -----------

The contens of cleanup.conf is showen below
--------- cat cleanup.conf -----------
, node1, node2
--------- cat cleanup.conf -----------


I get the following error showen below.
---------------- error ---------------
grep: can't open |/sbin/grep
grep: can't open -v
grep: can't open node1|/sbin/grep
grep: can't open -v
grep: can't open node2
/home/user1/cleanup.log
---------------- error ---------------


I have tryed to do an echo of $EXCLUDES and it seems to be ok, se below this line:

|/sbin/grep -v node1|/sbin/grep -v node2


But when I try to do an substitution i $CMD1 I get the error. Can someone tell me what I am doing wrong and how I can find a solution on me problem.

Regards Valle
 
Take a look at the eval shell builtin.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I have tryed to use the eval shell builtin on almost any variables in the script. But it dos not solve the problem.

Can you be more specific on where you want me to use the eval function?

Regards Valle
 
Have you tried this ?
eval CMD1=\`grep /var/opt/ignite/clients $LOG $EXCLUDES\`


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
That did it!
I had forgotten the
Thanks!

Regards Valle
 
what are you doing?
EXCLUDES=`sed 's/,/\|\/sbin\/grep -v/g' $CONF`
i read:
substitute all ',' with: '|/sbin/grep -v' in '$CONF'

a) '|' does not need to be masked
b) '/sbin/grep' is very new to me
c) why not a little simpler ?
put your exclude (line by line) in $CONF, g.e.:
nodeA
nodeB
...
nodeX
# this prints your list

grep /var/opt/ignite/clients $LOG |[ef]grep -v -f $EXCLUDES |sed -e 's/:.*//'

----- my way: put in $EXCLUDE something like

/node[1287ACq]/d
/\/var\/opt\/ignite\/clients/{;s/:.*//p;}

----- then call: sed -nf $EXCLUDE $LOG

don't forget, RTFMP :) guggach
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top