Visit The New, Modern Unix Linux Community

Passing eval value to a variable

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Passing eval value to a variable
# 1  
Passing eval value to a variable


I have a script that does an scp to a server and then gets the number of process running on that server, the o/P should be stored in a variable for further processing

eval `echo "ssh -q $Infa_user@$host 'csh -c $CMD '"`
CMD="ps -ef | grep -i ${INFA_REPO} | grep -v grep | wc -l"

the eval command works fine in the script and o/P the no of processes however when i put it a variable, i get an errror i.e

STATUS=`eval `echo "ssh -q $Infa_user@$host 'csh -c $CMD '"``

results in error : not found [No such file or directory.

Any idea's how to do that ?
# 2  
i found it

status=`eval "eval "echo "ssh -q $Infa_user@$host 'csh -c $CMD '"""`

works fine.
# 3  
Too many layers

No need for all the extra layers. On my machine, the following does the same thing:

$ cmd1="ps -efwww | grep sbin"
$ cmd2="bash -c '$cmd1'"
$ results=$(ssh -q myhost "$cmd2")

or simply

$ results=$(ssh -q myhost "$cmd1")

eval has its uses, but only at the Ph.D level Smilie

Last edited by vbe; 04-29-2009 at 05:37 AM.. Reason: removed faulty URL (for approval...)

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #374
Difficulty: Easy
In 2004, a new edition of the POSIX:2002 standard was released called POSIX:2004 (formally: IEEE Std 1003.1-2004).
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Eval and get awk output assigned to variable

I want to do 2 things in single line that is evaluating a command to get return code and store $2 of awk if the command exit code is 0. eval "ade desc ${filename}@@/<branch_name> | grep Version | awk '{print $2}' 2>&1 1>/dev/null" ret=$? echo "$ret $val" if then ... (3 Replies)
Discussion started by: ezee
3 Replies

2. Shell Programming and Scripting

Safe way to eval variable declarations?

Is there a safe way to evaluate variable declarations within a script whether they come from a .conf file, user input, or stdin? Example .conf file: port=21 user="$USER" # Hopefully allow this type of substitution domain="$DOMAIN" server="$(malicious... (4 Replies)
Discussion started by: Michael Stora
4 Replies

3. Shell Programming and Scripting

'eval' used in variable assignment

pattern1=book { x=1 eval echo \$pattern$x } book (this is the output) But when I assign a variable to the output of the eval it doesn't work unless I prefix 2 times backslash before $ as shown below. { a=`eval echo \\$pattern$x` echo $a } book Why here twice "\" has to be... (3 Replies)
Discussion started by: ravisingh
3 Replies

4. Shell Programming and Scripting

assignment to variable from eval command

Hi Gurus, I am having 2 parameters as below parm1=value1 parm2=parm1 I want to evaluate parm1 value using eval echo \$$parm2 and later i want to assign this value to other variable which i will be using in if statement like : if ]; then do this....... fi could you please suggest... (5 Replies)
Discussion started by: k_vikash
5 Replies

5. Shell Programming and Scripting

eval and variable assignment

Hi, i have an issue with eval and variable assignment. 1) i have a date value in a variable and that date is part of a filename, var1=20100331 file1=${var1} file2=${var2} file3=${var3} i am passing the above variables to a script via... (11 Replies)
Discussion started by: mohanpadamata
11 Replies

6. Shell Programming and Scripting

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

7. Shell Programming and Scripting

bin/sh eval variable assignment

Why can't I do this? eval "TEST=5;echo $TEST;"; THIS WORKS!! TEST=5;echo $TEST; (2 Replies)
Discussion started by: blasto333
2 Replies

8. Shell Programming and Scripting

How to assign eval value as Variable..

Im facing problem in assigning value of eval array variable as normal variable.. x=0 eval DATA${x}="FJSVcpcu" x=`expr $x + 1` eval DATA${x}="FJSVcsr" if x=0, type -> eval echo \$DATA$x , its give me FJSVcpcu i want assign this value into an variable as variable=`eval echo... (3 Replies)
Discussion started by: neruppu
3 Replies

9. UNIX for Advanced & Expert Users

Urgent-Reading eval result in a variable

Hi everyone, I do have the requirement to store the value of below result in a variable eval echo $a Please .... Help me , it's urgent to my sript Thanks in advance... (1 Reply)
Discussion started by: kaaakrishna
1 Replies

10. Shell Programming and Scripting

eval a variable that has a .

Hi, Is there any way that I can eval the following - eval abc.csv=def.csv I am getting the - bash: command not found error. thanks. (3 Replies)
Discussion started by: ttshell
3 Replies

Featured Tech Videos