Help in scripting, store value in variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help in scripting, store value in variable
# 8  
Old 09-13-2010
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).

Code:
/opt/dell/srvadmin/sbin/omreport about | grep -qx 'Version : 6.3.0' ; REPLY=$?
exit ${REPLY}

# 9  
Old 09-14-2010
try this:
Code:
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


Last edited by Franklin52; 09-14-2010 at 06:10 AM.. Reason: Please use code tags, thank you!
# 10  
Old 09-14-2010
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 ...

Code:
$ ./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 ...

Code:
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

Last edited by Scott; 09-14-2010 at 09:42 AM.. Reason: Code tags, please...
# 11  
Old 09-14-2010
Have you tried this proposition ?
Quote:
Originally Posted by methyl
Code:
/opt/dell/srvadmin/sbin/omreport about | grep -qx 'Version : 6.3.0' ; REPLY=$?
exit ${REPLY}

# 12  
Old 09-14-2010
Try this,

Code:
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

# 13  
Old 09-14-2010
Still showing same error ...

Code:
$ ./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.

.....Smilie

Last edited by Scott; 09-14-2010 at 09:54 AM.. Reason: Code tags
# 14  
Old 09-14-2010
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 .
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

I can't store value in the variable

!#bin/bash clear var= grep @gmail.com email.txt | wc -l echo $var echo $var exit 0 OUTPUT: 1000 _ _ Where _ represent space (no value or nothing) (4 Replies)
Discussion started by: Muhammad Rehan
4 Replies

2. Shell Programming and Scripting

How do I store stdout in a variable?

These seems ridiculously simple but I can't get it to work. Using korn shell and I want to pass in a flag to tell my echo statements to either write to the screen for debugging or a file if not. So I have something like: if ; then logout=&1 else logout='logfile.out' fi Then... (2 Replies)
Discussion started by: DJR
2 Replies

3. UNIX for Advanced & Expert Users

Help on Shell Scripting - to store output to a fixed file

Hi I have a file called "test.txt" and it looks like this x y z x/c y/c/b now, i want to run a command and its output will be like this x 10 y/c/b 20 z 78 -------- my requirement is, i want to add the command output to "test.txt" as like below x 10 y ... (1 Reply)
Discussion started by: siva kumar
1 Replies

4. Shell Programming and Scripting

how to store output to a variable

I need some help: 1) I have a out put from a shell script, the out put looks like this: Attempting privilege escalation using sudo ... List backups for CLTST: Start date Status Ret. Class Label -------------------- ------------ ------------ ... (2 Replies)
Discussion started by: samk
2 Replies

5. UNIX for Dummies Questions & Answers

How to store the value from python in shell scripting?

I am calling fab file from shell, and i am getting the output from python. How to store that value in shell? Eg:- I am taking the value using yaml file in python. Since i am calling python from shell, i need to store the value in variable or in array using shell, because my next call is running... (0 Replies)
Discussion started by: KarthikPS
0 Replies

6. Shell Programming and Scripting

cut and store last value of a variable into other

Hi All, I am a newbie to unix.starting my career in unix.need 1 help from you all..pls help.. i am passing a file name "abc_delta" as argument to my script1.sh. if file name contains "_delta" at last then echo pass else fail.how to fix it. Note:file name will always contain "_delta" at... (10 Replies)
Discussion started by: pradeepcarya
10 Replies

7. Shell Programming and Scripting

how to store output into variable-in unix shell scripting

Hi, Output of "ps -o etime,time,pcpu,pmem,fname -C sbd-java" command is - Elapsed Time %cpu %MEM COMMAND 02:14:03 00:03:28 2.5 6.3 sbd-java Can anyone tell me, how to store the the value 2.5 in a variable? When I say echo $X where x is a variable then... (4 Replies)
Discussion started by: pspriyanka
4 Replies

8. Shell Programming and Scripting

Not able to store command inside a shell variable, and run the variable

Hi, I am trying to do the following thing var='date' $var Above command substitutes date for and in turn runs the date command and i am getting the todays date value. I am trying to do the same thing as following, but facing some problems, unique_host_pro="sed -e ' /#/d'... (3 Replies)
Discussion started by: gvinayagam
3 Replies

9. UNIX for Dummies Questions & Answers

How to Store command O/P to a variable...

Hi all.. I got a problem.. Its easy to redirect o/p to a file.. But Is it possible to redirect the O/P to a variable? For example: I've a command in my script: string1=cut -d ':' -f2 file.txt When I do: echo $string1 The value is empty... Pls suggest me how to store the value... (7 Replies)
Discussion started by: smartbuddy
7 Replies

10. Shell Programming and Scripting

To store the output in a variable

Hi, I am getting the following error while executing the script. Please can someone throw some light where is the problem. Many thanks. ./check: temp: not found The directory related to SEP instance 4 does not exist. The script is as follows. SEP_APP="/scp/sepx/app... (2 Replies)
Discussion started by: Sudhakar333
2 Replies
Login or Register to Ask a Question