Renjesh
September 13, 2010, 6:40am
1
Hi all,
I have a script in which i need to run a command like "/opt/dell/srvadmin/sbin/omreport about" and output will be something like
Version : 6.3.0
Copyright : Copyright (C) xxx Inc. 1995-2010 All rights reserved.
Company : xxx Inc.
In this i need to save the version to a variable and Ensure that the version is 6.3.0.
If the version is 6.3.0 exit with a return code of 0 (success)
If the version is not 6.3.0 exit with a failure code
Please help me out in this ...
Thanks in advance
Try this,
#!/bin/sh
ver=`opt/dell/srvadmin/sbin/omreport about | awk 'NR==1&&/Version/{print $3}'`
echo $ver
if [ $ver == "6.3.0" ] ; then exit 0 ; else exit 1; fi
Renjesh
September 13, 2010, 7:30am
3
It is throwing an error like
line 2: ver: command not found
line 4: [: =: unary operator expected
There should not be space between ver= and `.
ver=`opt/dell/srvadmin/sbin/omreport about | awk 'NR==1&&/Version/{print $3}'`
echo $ver
if [ "$ver" == "6.3.1" ] ; then exit 0 ; else exit 1; fi
hi,
If your output contains only one Version then below code works:
a=`/Sep/example.sh | awk -F: '/Version/ { print $2 }'`
echo $a
Scott
September 13, 2010, 8:24am
6
Slight correction, if I may?
a=`/Sep/example.sh | awk '/Version/ { print $NF }'`
echo $a
Otherwise you'd need -F"[ :]" to handle the spaces as well as the colon.
frans
September 13, 2010, 8:53am
7
V=$(/opt/dell/srvadmin/sbin/omreport about | grep Version)
[ "${V#*: }" = "6.3.0" ]
The exit code of the script is the exit code of last command
Version=6.3.0 => $?=0
otherwise $?=1
methyl
September 13, 2010, 8:59am
8
Using the Exact Match feature of "grep" we can avoid accidental matches such as 6.3.07 . In this context the exit code from "grep" will be either zero (success) or one (string not found).
/opt/dell/srvadmin/sbin/omreport about | grep -qx 'Version : 6.3.0' ; REPLY=$?
exit ${REPLY}
easwam
September 14, 2010, 12:35am
9
try this:
VAR1=$(/opt/dell/srvadmin/sbin/omreport about | cut -f2 -d ":" | sed 's/.* //')
echo "Version is: ${VAR1}"
if [ "${VAR1}" == "6.3.0" ] ; then exit 0 ; else exit 1; fi
Renjesh
September 14, 2010, 8:18am
10
Ya , now it's working ... thanks a lot guys ...
---------- Post updated at 06:41 PM ---------- Previous update was at 03:39 PM ----------
Still showing syntax error ...
$ ./Dell_OMSA_6_30
script Dell_OMSA_6_30 executing 2010/09/14 07:06:51
./Dell_OMSA_6_30[56]: 0403-057 Syntax error at line 102 : `"' is not matched.
Code area where it is creating error ...
ver=`/opt/dell/srvadmin/sbin/omreport about | awk 'NR==1&&/Version/{print $3}'`
if [ "$ver" == "6.3.0" ]; then exit 0 ; else exit 1; fi
Thanks
Renjesh Raju
frans
September 14, 2010, 8:29am
11
Have you tried this proposition ?
Try this,
ver=$(/opt/dell/srvadmin/sbin/omreport about | awk 'NR==1&&/Version/{print $3}')
if [ "$ver" == "6.3.0" ] ; then exit 0 ; else exit 1; fi
Renjesh
September 14, 2010, 8:47am
13
Still showing same error ...
$ ./Dell_OMSA_6_30
script Dell_OMSA_6_30 executing 2010/09/14 07:46:03
./Dell_OMSA_6_30[56]: Syntax error at line 102 : `"' is not matched.
.....
methyl
September 14, 2010, 9:42am
14
The error message is about unmatched quotes of some sort.
If you can't see the error, please post the whole script Dell_OMSA_6_30 .