Sponsored Content
Top Forums Shell Programming and Scripting Declare and grep a variable via ssh/remote/loop Post 303021684 by kenshinhimura on Tuesday 14th of August 2018 03:23:18 PM
Old 08-14-2018
Declare and grep a variable via ssh/remote/loop

If I am running a bash command, and some awk getting the ethernet adapter on the local machine. It works fine. But if I will run it from the remote, it is EMPTY on echo and throwing error in grep.
Thank you



This work perfectly fine
Code:
$ f=`/sbin/ip a|grep 127.127 | awk '{print $NF }' ` ; ip a| grep $f

6: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN
    inet 127.127.127.127/32 brd 127.127.127.127 scope host br0

$ f=`/sbin/ip a|grep 127.127 | awk '{print $NF }' ` ; ip a| grep $f|grep scope
    inet 127.127.127.127/32 brd 127.127.127.127 scope host br0

$ f=`/sbin/ip a|grep 127.127 | awk '{print $NF }' ` ; ip a| grep $f|grep scope
    inet 127.127.127.127/32 brd 127.127.127.127 scope host br0
$

Now from my remote machine:
Code:
$ for i in REMOTEserver; do  ssh $i " f=`/sbin/ip a|grep 127.127 | awk '{print $NF }' ` ; echo $f "  ; done


$ for i in REMOTEserver; do  ssh $i " f=`/sbin/ip a|grep 127.127 | awk '{print $NF }' ` ; echo \$f "  ; done

$ for i in REMOTEserver; do  ssh $i " f=`/sbin/ip a|grep 127.127 | awk '{print $NF }' ` ; echo $f "  ; done


$ for i in REMOTEserver; do  ssh $i " f=`/sbin/ip a|grep 127.127 | awk '{print $NF }' ` ; ip a|grep  $f "  ; done
bash: ip: command not found
Usage: grep [OPTION]... PATTERN [FILE]...
Try 'grep --help' for more information.

$

------ Post updated at 02:23 PM ------

Please close this, i figured it out.
Thank you
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

declare, assign variables using array, counter, loop

using bash Tru64... converting DCL to shell... any tips to make this work would be greatly appreciated. Below is my failed attempt to assign command line input to variables by first declaring an array. I use a counter to create unique variables in a loop through the array. I need to call... (3 Replies)
Discussion started by: egkumpe
3 Replies

2. Shell Programming and Scripting

BASH : Using declare in a loop

I have a config file that needs to be formatted before it's sourced to a script. I've been formatting it with sed and dropping it in /tmp then sourcing it from there. I'd like to just format the config file with sed then declare the variables without having to create a temporary file in /tmp. So... (2 Replies)
Discussion started by: crs6785
2 Replies

3. UNIX for Dummies Questions & Answers

declare variable

hi to all, i am trying to declare a variable as an integer in unix shell script. i search the web for a way to do it but it doesnt work. i tried "define -i" and "declare" but that doesnt work. if somebody knows another way to declare a variable as integer please help me. thank you (2 Replies)
Discussion started by: omonoiatis9
2 Replies

4. Shell Programming and Scripting

while loop stops after first iteration - remote ssh exit command problem?

I have written the following script to update some Debian boxes. #!/bin/bash mxg_hosts_file="/etc/mxg/ssh-hosts" while read line ; do mxg_host="$(echo ${line} | awk -F":" '{print $1}')" mxg_port="$(echo ${line} | awk -F":" '{print $2}')" echo "Connecting and Upgrading... (3 Replies)
Discussion started by: jelloir
3 Replies

5. Shell Programming and Scripting

ssh sending local variable to remote system

I am running a useradd script, which works locally but I want to take some of that local information and send it to a remote system, ssh keys are set up between the two systems. I am attaching the script, look at the section titled "Sending information to FTP2" Removed attachment, added... (0 Replies)
Discussion started by: slufoot80
0 Replies

6. Shell Programming and Scripting

how to declare variable in perl

how can i declare variable in perl. for BLOCK in /sys/block/emcpow* (3 Replies)
Discussion started by: learnbash
3 Replies

7. Shell Programming and Scripting

Ssh to remote server loop is breaking

hi All, cat login.list server1 userid1 server2 userid2 server3 userid3 ---------------------------------------- #SSHSCRIPT.ksh FILE=login.list while read vah vah_id do ssh $vah -l $vah_id "pwd" done < "$FILE" ----------------------------------------- When i... (2 Replies)
Discussion started by: raghur77
2 Replies

8. Shell Programming and Scripting

Remote command in variable using ssh

Hi, I've an issue in a shell script: I'm opening an ssh connection to a remote server, then I want to store the result of a ls command in a variable, but it doesn't work: the ls is done on the local machine. ssh user@server << EOF ls # works as expected (ls is done remotely) test=`ls` # the... (1 Reply)
Discussion started by: seloum57
1 Replies

9. Shell Programming and Scripting

Input to while loop in remote machine using ssh

Hello I am writing a script in a local machine, i am using ssh, here i am not able to using back ticks & input file to while loop. here is my script ssh -q server1 a=`ps -ef | grep ccms | awk {print $1}` b=`ps -ef | grep mss | awk {print $1}` # above lines are not working, so i redirected... (12 Replies)
Discussion started by: nanz143
12 Replies

10. Shell Programming and Scripting

Delete line from remote file over ssh passing variable

I have a variable called $a1 which maps to something like "http://servername proxy1 count http" and a lots of entries in a file on remote server. If I have the following in my .sh script: sed -i "\%$a1%d" mylog.txtthe line is deleted from mylog.txt. Great. I'm trying now to remvoe this from a... (3 Replies)
Discussion started by: say170
3 Replies
OCI_FIELD_PRECISION(3)													    OCI_FIELD_PRECISION(3)

oci_field_precision - Tell the precision of a field

SYNOPSIS
int oci_field_precision (resource $statement, mixed $field) DESCRIPTION
Returns precision of the $field. For FLOAT columns, precision is nonzero and scale is -127. If precision is 0, then column is NUMBER. Else it's NUMBER(precision, scale). PARAMETERS
o $statement - A valid OCI statement identifier. o $field - Can be the field's index (1-based) or name. RETURN VALUES
Returns the precision as an integer, or FALSE on errors. EXAMPLES
Example #1 oci_field_precision(3) Example <?php // Create the table with: // CREATE TABLE mytab (c1 NUMBER, c2 FLOAT, c3 NUMBER(4), c4 NUMBER(5,3)); $conn = oci_connect("hr", "hrpwd", "localhost/XE"); if (!$conn) { $m = oci_error(); trigger_error(htmlentities($m['message']), E_USER_ERROR); } $stid = oci_parse($conn, "SELECT * FROM mytab"); oci_execute($stid, OCI_DESCRIBE_ONLY); // Use OCI_DESCRIBE_ONLY if not fetching rows $ncols = oci_num_fields($stid); for ($i = 1; $i <= $ncols; $i++) { echo oci_field_name($stid, $i) . " " . oci_field_precision($stid, $i) . " " . oci_field_scale($stid, $i) . "<br> "; } // Outputs: // C1 0 -127 // C2 126 -127 // C3 4 0 // C4 5 3 oci_free_statement($stid); oci_close($conn); ?> NOTES
Note In PHP versions before 5.0.0 you must use ocicolumnprecision(3) instead. This name still can be used, it was left as alias of oci_field_precision(3) for downwards compatability. This, however, is deprecated and not recommended. SEE ALSO
oci_field_scale(3), oci_field_type(3). PHP Documentation Group OCI_FIELD_PRECISION(3)
All times are GMT -4. The time now is 04:43 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy