Re: Passing variables to remote hosts through ssh

Earthdog <nobody@xxxxxxxxxx> writes:


I have a central administration server that has root-level public key
access to my other hosts. I run scripts that use ssh to execute commands
on all my hosts. How do I pass variables through ssh?

For example, suppose I want to create a directory called /tmp/newdir on
100 hosts:



for i in `cat /long/list/of/hosts`

ssh $i '/usr/bin/mkdir /tmp/$DIRNAME'

This doesn't work, because $DIRNAME doesn't get passed to the remote host.
How can I make it work without hardcoding newdir in the ssh line?

change the ' to "
' says do not expand the stuff inside. " says do expand the stuff inside So
if you do
ssh $i "/usr/bin/mkdir /tmp/$DIRNAME"
the $DIRNAME will be expanded to newdir on the local machine.


Relevant Pages

  • Re: SSH: remote login returns "invalid user"
    ... do you differentiate between client hosts and server hosts and most ... with your current account being "brownh" and you ... At present, I have three or four hosts on a LAN, and I can ssh from ...
  • Re: openssh concerns
    ... in to ssh. ... No protection is afforded against DNS poisoning, ... Hosts with no reverse DNS ... big service providers like google and hotmail. ...
  • Re: IPV6 & pf
    ... das einzige was mir auffällt sind icmpv6 Fehler. ... Oben sieht man die funktionierende Verbindung, ... Wenn Du auf beiden Hosts tcpdump vergleichst, ... ssh auch direkt pingen. ...
  • Re: Whats the deal on the -X vs -Y thing?
    ... As a quick fix you could use something like this as your remote ssh ... chain is compromised (eg at either the tty layer, X11 forwarding port ... forwarding would not be needed on the intermediate hosts. ...
  • Re: what checking should FW-1 perform?
    ... >> some selected hosts on the other side. ... >> So I am going to supply the source IP, username and SSH public dsa key ... >> for each client with a list of IPs want to connect to. ...