passing the output of cmd from "eval" to a variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting passing the output of cmd from "eval" to a variable
# 1  
Old 07-15-2009
passing the output of cmd from "eval" to a variable

Hello,

I need help with the eval command.

I have been building a lengthy cmd using eval, and I need to create $var from the output of the cmd. Here is what I have.

Code:
 
Out=/dfezz1/output.txt
Node="'LPAR Info:'"
Gr3p0=" |grep"
Printc=" prtconf"
Output1=" 1>>$Out 0>&1"
Cat1="cat /dfezz1/tmp.txt"
 
eval "$Cat1 $Gr3p0 $Node $Output1"
cmd = cat /defezz1/tmp.txt |grep LPAR Info: 1>>$Out 0>&1

I have tried ...
With and without double quotes "" and __
Code:
 
eval "VAR=$Cat1 $Gr3p0 $Node $Output1"

I am running several eval grep-ing for various info and what I want to do is format the outputs and comma separate or use pipes and import it into excel.

so sometime like this after I get the eval --> $VAR

cat $VAR1 || $VAR2 || $VAR3 || >> results.txt .... then pull it into a .xls

Thanks
-Dfezz1
# 2  
Old 07-15-2009
If I understand correctly you don't need eval/variable and you don't need cat at all. Search your shell man pages for command substitution. You just need to format and spool the output (using printf, for example).
# 3  
Old 07-15-2009
Thanks, but these commands I am buiding seem to require eval, due to whittespace and | symbols ect. the cat was only an example to show what I wanted to do with the formating, what I really need to know is how do take the output from my eval(command) and make it a variable like ---

Code:
 
eval(VAR1="$Cat1 $Gr3p0 $Serial $Output1")

but I can't get the syntex correct and I can't find a good example, I know it can be done and once I have that, the rest is cake!

once I get this, i will create a readable , maintainable spreadsheet, with all of my server info

example: hostname || IP || firmware || OS ver. || Memory || etc.

Then this can be ran and update

Last edited by dfezz1; 07-15-2009 at 04:54 PM..
# 4  
Old 07-16-2009
Try:
Code:
cmd="$Cat1 $Gr3p0 $Node $Output1"
eval VAR=\$\($cmd\)

# 5  
Old 07-16-2009
Thanks that worked KINDA...
I am getting the value written to the output file, not assigned to the variable ???

So

Code:
 
cmd="$Cat1 $Gr3p0 $Node $Output1"
eval VAR=\$\($cmd\)

works, but when I echo or print $VAR it's empty. ????

But one step closer thanksSmilie
# 6  
Old 07-16-2009
Oh, right. But that's the result of redirecting the output. If you want the result of the command to be both written to a file and printed to the standard output, use 'tee' command.
# 7  
Old 07-16-2009
I want the ouput written to a file and assigned to a variable so I can format it
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Using a single "find" cmd to search for multiple file types and output individual files

Hi All, I am new here but I have a scripting question that I can't seem to figure out with the "find" cmd. What I am trying to do is to only have to run a single find cmd parsing the directories and output the different file types to induvidual files and I have been running into problems.... (3 Replies)
Discussion started by: swaters
3 Replies

2. Shell Programming and Scripting

Perl open(CMD, "cmd |"); buffering problem..

Hello, There's a third-party application's command that shows the application's status like "tail -f verybusy.log". When use the command, the output comes every 1-sec. but when it goes in a script below the output comes every 8-sec...What is the problem and how can I fix it? open(CMD,... (2 Replies)
Discussion started by: Shawn, Lee
2 Replies

3. Shell Programming and Scripting

Storing output of "time" command to a variable

Hi all, I am new to Linux/shell scripting having moderate knowledge. In my script, I need to get execution time of a command (say 'ls') in mili seconds level. For this i tried using "time" command to retrieve the total execution time in milli seconds. But, the problem is that, how to save... (9 Replies)
Discussion started by: happening_linux
9 Replies

4. Shell Programming and Scripting

"Join" or "Merge" more than 2 files into single output based on common key (column)

Hi All, I have working (Perl) code to combine 2 input files into a single output file using the join function that works to a point, but has the following limitations: 1. I am restrained to 2 input files only. 2. Only the "matched" fields are written out to the "matched" output file and... (1 Reply)
Discussion started by: Katabatic
1 Replies

5. UNIX for Dummies Questions & Answers

Explanation of "total" field in "ls -l" command output

When I do a listing in one particular directory (ls -al) I get: total 43456 drwxrwxrwx 2 root root 4096 drwxrwxrwx 3 root root 4096 -rwxrwxr-x 1 nobody nobody 3701594 -rwxrwxr-x 1 nobody nobody 3108510 -rwxrwxr-x 1 nobody nobody 3070580 -rwxrwxr-x 1 nobody nobody 3099733 -rwxrwxr-x 1... (1 Reply)
Discussion started by: proactiveaditya
1 Replies

6. Shell Programming and Scripting

store the output of "find" command in a variable?

I intend to find the path/full location of a file(filename given by user thru "read filenme") using "find" or any other command and then store it's output in a variable for some other processing. But struggling to put all things together (i.e finding the fully qualified location of that file and... (4 Replies)
Discussion started by: punitpa
4 Replies

7. Shell Programming and Scripting

How to store the output of "time dd if= of=" in a variable

Hi All, I need to store the real seconds of the following command in a variable. How could it be done? time $(dd if=/dev/zero of=/dev/sda1 bs=512 count=2048;sync) Thanks, Amio (12 Replies)
Discussion started by: amio
12 Replies

8. Shell Programming and Scripting

assign shell var output of cmd "wc"

how do I feed output of "wc" to a shell script variable "countBcp"? (2 Replies)
Discussion started by: devy
2 Replies

9. Debian

Debian: doubt in "top" %CPU and "sar" output

Hi All, I am running my application on a dual cpu debian linux 3.0 (2.4.19 kernel). For my application: <sar -U ALL> CPU %user %nice %system %idle ... 10:58:04 0 153.10 0.00 38.76 0.00 10:58:04 1 3.88 0.00 4.26 ... (0 Replies)
Discussion started by: jaduks
0 Replies

10. Shell Programming and Scripting

How to get Find command work with a variable passing "*" value?

Hi guy, I have a problem to pass a variable containing '*' value to FIND command. below is the script. It doesn't work by submit below command: rmf.sh name '*.txt' or rmf.sh name *.txt I've tried either optn="-name '$2'" or optn="-name $2"., and there is no luck. ### (script... (5 Replies)
Discussion started by: unxuser
5 Replies
Login or Register to Ask a Question