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
ARP(3pm)						User Contributed Perl Documentation						  ARP(3pm)

NAME
ARP - Perl extension for creating ARP packets SYNOPSIS
use Net::ARP; Net::ARP::send_packet('lo', # Device '127.0.0.1', # Source IP '127.0.0.1', # Destination IP 'aa:bb:cc:aa:bb:cc', # Source MAC 'aa:bb:cc:aa:bb:cc', # Destinaton MAC 'reply'); # ARP operation $mac = Net::ARP::get_mac("eth0"); print "$mac "; $mac = Net::ARP::arp_lookup($dev,"192.168.1.1"); print "192.168.1.1 has got mac $mac "; IMPORTANT Version 1.0 will break with the API of PRE-1.0 versions, because the return value of arp_lookup() and get_mac() will no longer be passed as parameter, but returned! I hope this decision is ok as long as we get a cleaner and more perlish API. DESCRIPTION This module can be used to create and send ARP packets and to get the mac address of an ethernet interface or ip address. send_packet() Net::ARP::send_packet('lo', # Device '127.0.0.1', # Source IP '127.0.0.1', # Destination IP 'aa:bb:cc:aa:bb:cc', # Source MAC 'aa:bb:cc:aa:bb:cc', # Destinaton MAC 'reply'); # ARP operation I think this is self documentating. ARP operation can be one of the following values: request, reply, revrequest, revreply, invrequest, invreply. The default ARP operation is reply. get_mac() $mac = Net::ARP::get_mac("eth0"); This gets the MAC address of the eth0 interface and stores it in the variable $mac. The return value is "unknown" if the mac cannot be looked up. arp_lookup() $mac = Net::ARP::arp_lookup($dev,"192.168.1.1"); This looks up the MAC address for the ip address 192.168.1.1 and stores it in the variable $mac. The return value is "unknown" if the mac cannot be looked up. SEE ALSO
man -a arp AUTHOR
Bastian Ballmann [ Balle@chaostal.de ] http://www.datenterrorist.de COPYRIGHT AND LICENSE
Copyright (C) 2004-2007 by Bastian Ballmann This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.1 or, at your option, any later version of Perl 5 you may have available. perl v5.14.2 2009-04-24 ARP(3pm)
All times are GMT -4. The time now is 01:37 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy