3

I wrote a script that SSH to remote servers in loop and run a command, it gets hung after running on last server.Here is my loop script -

cat server | while read serName
        do
                cat cmmnds| while read line
                do
                 result=`ssh -f $serName  $line`
                 echo -n ",$result" >> test.csv
        done
echo " " >> test.csv
done

Here is how it errors out in the end and have to control+C for exiting out

Cannot fork into background without a command to execute.
ssh: illegal option -- d

usage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
           [-D [bind_address:]port] [-e escape_char] [-F configfile]
           [-I pkcs11] [-i identity_file]
           [-L [bind_address:]port:host:hostport]
           [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
           [-R [bind_address:]port:host:hostport] [-S ctl_path]
           [-W host:port] [-w local_tun[:remote_tun]]
           [user@]hostname [command]
Cannot fork into background without a command to execute.
OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
Cannot fork into background without a command to execute.

Any clue ??

Dee
  • 31
  • Add set -x before that loop to get a trace of what's going on. Evidently one of your variables doesn't contain what you think it does. Properly double-quoting variable expansions may help. Or it could be as simple as having a blank line. – Gilles 'SO- stop being evil' Jul 17 '15 at 22:56
  • I'd go with there being a blank line in each of the two source files. – Chris Davies Jul 17 '15 at 23:34
  • And please indent your code properly. – G-Man Says 'Reinstate Monica' Jul 17 '15 at 23:53