how to store output into variable-in unix shell scripting


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to store output into variable-in unix shell scripting
# 1  
Old 04-06-2011
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 output should be 2.5 only

Last edited by pspriyanka; 04-06-2011 at 08:56 AM.. Reason: space given in table
# 2  
Old 04-06-2011
Quote:
Originally Posted by pspriyanka
Can anyone tell me, how to store the the value 2.5 in a variable?
Read this thread, you will just have to filter out what interests you.

I hope this helps.

bakunin
# 3  
Old 04-06-2011
Thanks for helping me :-)
it's working using the following command-


X=`ps -o etime,time,pcpu,pmem,fname -C sbd-java --no-heading|awk '{print $3 }'`;

echo $X

output-2.5
# 4  
Old 04-06-2011
Quote:
Originally Posted by pspriyanka
[code]X=`ps -o etime,time,pcpu,pmem,fname -C sbd-java --no-heading|awk '{print $3 }'`[code]
You shouldn't use backticks at all! They are outdated and only supported by the shell for compatibility reasons. What's more, they can't be nested. Use "$(...)" instead of "`...`".

I hope this helps.

bakunin
# 5  
Old 04-07-2011
X=`ps -o etime,time,pcpu,pmem,fname -C sbd-java --no-heading|awk '{print $3 }'`;

echo $X

output-2.5

(This is the code for shell script working properly, i want use same application in perl script.
Is their any change required in above code.i have tried usind the same code in perl but its not working...)

can you plz tell me what changes need to be do??
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to get the for loop output from a remote server in UNIX shell scripting?

Hi, I am using ksh , when i try to use for loop i am getting the expected output. $for variable in $(ps -fu user | grep -i something/ | grep -i something | grep -v grep | awk '{print $2}');do > grep $variable /tmp/some_path/*/* > done when tried the below to remote server, getting... (4 Replies)
Discussion started by: karthikram
4 Replies

2. 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

3. 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

4. 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

5. Shell Programming and Scripting

generate tabular output from an input text file in unix shell scripting

Hi, I have the output (as below) which i want it to be in a table. For e.g. space utilization in PSE on path /logs is 0% space utilization in PSE on path /logs/tuxedo/tuxlsp is 16% space utilization in PSE on path /ldvarlsp/lsp/log is 37% space utilization in PSE on path /home is 6%... (7 Replies)
Discussion started by: pkbond
7 Replies

6. Shell Programming and Scripting

store sqlplus output in variable

hi how can i store sqlplus output to a variable in sh script (not bash) Thanks MM (1 Reply)
Discussion started by: murtymvvs
1 Replies

7. 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

8. Shell Programming and Scripting

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... (13 Replies)
Discussion started by: Renjesh
13 Replies

9. Shell Programming and Scripting

Assigning value of SQL output to a variable in shell scripting

I am trying to assgn the output of the select statement to a variable, like this "VARIABLE_NAME=$ db2 "select COLUMN_NAME_1 from TABLE_NAME where COLUMN_NAME_2='VALUE_TO_CHECK'"; " but the value that is getting into VARIABLE_NAME is "COLUMN_NAME_1 ----------------- VALUE 1... (3 Replies)
Discussion started by: sgmini
3 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