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
# 1  
Old 09-13-2010
Error Help in scripting, store value in variable

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
- Renjesh Raju
# 2  
Old 09-13-2010
Try this,
Code:
#!/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

# 3  
Old 09-13-2010
It is throwing an error like

line 2: ver: command not found

line 4: [: =: unary operator expected
# 4  
Old 09-13-2010
There should not be space between ver= and `.

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

# 5  
Old 09-13-2010
hi,

If your output contains only one Version then below code works:

Code:
a=`/Sep/example.sh | awk -F: '/Version/ { print $2 }'`
echo $a

# 6  
Old 09-13-2010
Quote:
Originally Posted by dragon.1431
hi,

If your output contains only one Version then below code works:

Code:
a=`/Sep/example.sh | awk -F: '/Version/ { print $2 }'`
echo $a

Slight correction, if I may?

Code:
a=`/Sep/example.sh | awk '/Version/ { print $NF }'`
echo $a

Otherwise you'd need -F"[ :]" to handle the spaces as well as the colon.
# 7  
Old 09-13-2010
Code:
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
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