-1

I would like to SSH to a list of servers, to gather data in an automated fashion.

Right now my session begins with msg "Pseudo-terminal will not be allocated because stdin is not a terminal." and continues on without ever being connected to the remote servers.

If I remove '-n' form the SSH line, it connects to the remote server and stops the script execution, until the SSH session is disconnected.

 for host in $(cat host_list);
    do
        ssh -n -o stricthostkeychecking=no $host
        var1=$(awk -F '.' '{print $1}' some_file )
        var2=$(some_command $var1)
        echo $var2
    done

Original Post (For context if desired): Data Extrapolation & Bash Logic within Expect Script

pynexj
  • 19,215
  • 5
  • 38
  • 56
Mark
  • 1
  • 2
  • 1
    I'm a bit confused what this script is trying to do. Do you want the commands in `$()` to be executed on the remote machine? – Kiersten Arnold Nov 27 '17 at 19:20
  • Yes that is correct. – Mark Nov 27 '17 at 19:23
  • forget the loop for a moment and show us what command(s) you want to run on the remote host; also tell us where `some_file` and `some_command` reside ... locally or on the remote host(s) – markp-fuso Nov 27 '17 at 19:24
  • Everything in loop (After SSH) is to be executed and exists on the remote server. host_list is the only file aside form the script itself that will exist locally. – Mark Nov 27 '17 at 19:30
  • to solve the "Pseudo-terminal will not be allocated ..." problem, try `ssh -t -t -t -n -o ...` (yes, really, multiple `-t`s ;-) ) . Good luck. – shellter Nov 27 '17 at 20:55

2 Answers2

0

You got a useless use of cat award

Use a while loop instead. Also dont forget to escape dollar sign inside the awk program which you want to run remotely to avoid expansion locally:-

while read host
do
        ssh -n -o StrictHostKeyChecking=no $host "awk -F'.' '{ print \$1 }' some_file"

done < host_list
Yoda
  • 435
  • 2
  • 7
-1

It's looks like what you want is to grab info from a remote file and then do some processing. What you'll need to do is execute the awk command from ssh like:

cmd="awk -F '.' '{print $1}' some_file" for host in $(cat host_list); do var1=$(ssh -o stricthostkeychecking=no $host $cmd) var2=$(some_command $var1) echo $var2 done

Kiersten Arnold
  • 1,840
  • 1
  • 13
  • 17
  • 1
    Why are you putting the command in a variable? Without proper quoting or escaping, the value in `cmd` will contain *the current script's* value for `$1` rather than the literal string `$1` in the Awk script, which is probably a syntax error. More generally, you need to review https://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-shell-variable – tripleee Nov 27 '17 at 20:32