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.

 
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 __

 
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

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

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

 
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

Try:

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

Thanks that worked KINDA...
I am getting the value written to the output file, not assigned to the variable ???

So

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

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

But one step closer thanks:b:

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.

I want the ouput written to a file and assigned to a variable so I can format it

Out=/dfezz1/output.txt
Node="'LPAR Info:'"
Gr3p0=" |grep"
Printc=" prtconf"
Output1=" | tee -a $Out"
Cat1="cat /dfezz1/tmp.txt"

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

I have re-written the script.

here is what I ended up going with and it works;

I ran a prtconf statement and wrote it out to /dfezz/tmp.txt then I cat and grep for what I need, the other way I was doing it was running that cmd several times.

   
NodeName=`eval "cat /dfezz/tmp.txt |grep 'LPAR Info:'"`
SerialNum=`eval "cat /dfezz/tmp.txt |grep 'Machine Serial Number:'"`
FWare=`eval "cat /dfezz/tmp.txt |grep 'Firmware Version:'"`
Model=`eval "cat /dfezz/tmp.txt |grep 'System Model:'"`
Proc=`eval "cat /dfezz/tmp.txt |grep 'Processor Type:'"`
ChipSpeed=`eval "cat /dfezz/tmp.txt |grep 'Processor Clock Speed:'"`
Memory=`eval "cat /dfezz/tmp.txt |grep 'Memory Size:'| grep -v 'Good Memory Size:'"`
OSver=`eval "cat /dfezz/tmp2.txt"`
echo $OSver
echo "$NodeName $Space $SerialNum $Space $FWare $Space $Model $Space $Proc $Space $ChipSpeed $Space $Memory $Space OS Level: $OSver" 1>>$Out 0>&1