#!/bin/sh
set -x
for i in `cat a`; do
#sleep 3
print $i >> server.txt
sleep 5
if test -d `vtask $i "' ls -lrt /opt/log/ '" ` ;
then
print $i >> 12.5.txt
else
print $i >> 12.0.txt
fi
done
where the vtask is a command line execution script
in my 'a' file I have some servers
I want to check if the log directory exists in the servers if it exists then it should update in the 12.5.txt else if the log directory does not exists if should update in the 12.0.txt directory.
The above command gives me full output of the text file since it matches all the 12.5.0.2307 I want to grep just '12.5.0.2307' alone...I don't want the whole line just the 12.5.0.2307, how to achieve this?
Hi, My box is aix and the grep does not support -o option. Any other suggestions? ofcourse I can think about awk but not sure how to get the word alone from the output
what I want to know is even if the command does not find '12.5.0.2307' version in the server it still goes to the 12.5.txt file, I want if the command does not find the version as '12.5.0.2307' or it got disconnected it should go to 12.0.txt
The version.txt file has the following entries
12.5.0.2307
12.5.0.2307
12.5.0.2307
not sure why another '1' is added after 12.5.0.23071
The value of ? ( $? ) which you are testing is for the echo $ver statement (which will almost always be true (0)) and subsequently, only 12.5.txt will be appended to.
You don't seem to be needing the awk command.
Try:
#!/bin/sh
set -x
for i in `cat serverlist`; do
sleep 2
vtask $i ". /etc/profile.CA all; dsmver" > version.txt
#ver=`awk '{while(match($0,/12\.5\.0\.2307/)) { print substr($0,RSTART,RLENGTH) sub(/12\.5\.0\.2307/,"")}}' version.txt | sort -u`
#echo $ver
#if [ $? -eq 0 ];
if fgrep -q "10.12.2.2307" version.txt 2>/dev/null
then
print $i >> 12.5.txt
else
print $i >> 12.0.txt
fi
done