I use following shell script
Revised code
Code:
host_list="/home/campus27/zwang10/bin/hostlist"
HOSTS=`cat $host_list`
cp /dev/null hostlist_available
for line in $HOSTS
do
ssh -o ConnectTimeout=1s $line true &>/dev/null
RESULT=$?
if [ $RESULT -eq 0 ]
then
output=$(ssh -f $line "w" | tail -n+3 | awk '{print $1}')
if [[ $RESULT -eq 0 ]] && [[ -z $output || $output == 'zwang10' ]]
then
echo $line
echo $line >> hostlist_available
fi
fi
done
I would like to do following:
**Under the condition that
holds,
either
Code:
[ -z $(ssh -f $line "w" | tail -n+3 | awk '{print $1}') ]
or
Code:
$(ssh -f $line "w" | tail -n+3 | awk '{print $1}') only contains string "zwang10"
holds, we still continue the loop.**
The command
Code:
$(ssh -f $line "w" | tail -n+3 | awk '{print $1}') ]
will output like following cases:
Only one of my name
Several my names
Some others name
Other names and mine
Code:
jack
zwang10
zwang10
How can test whether the output only contains my name `zwang10`?
Revised requirement
Code:
$output == 'zwang10'
only output yes when there is only one
. However, I also want it will output yes when there are multiple zwang10's and no other names.