Reputation: 1445
I am writing a script in Unix that needs to:
Unfortunately, I can't do this because once the script logs in via ssh, it can't see the text file. So I am trying to pass a local text to the ssh command, so it will see the text file.
Text file is resembles this
user@servername1
user@servername2
user@servername3
... etc
I looked on a previous answer from SuperUser, but their solution just returns errors for me.
ssh user@servername < text.txt
#stty: : Invalid argument
#sh: user@servername1: not found
#sh[2]: user@servername2: not found
#sh[3]: user@servername3: not found
#...etc
Upvotes: 3
Views: 9982
Reputation: 17304
As an alternative to @glennjackman's two connections to copy and then execute...
Since you can pipe commands to ssh, which is quite similar to your example,
echo "ls" | ssh localhost
All you need is something in the middle to interpret the text file. For example...
cat text.txt | sed 's/^/finger /' | ssh user@servername
#or
cat text.txt | ssh user@servername xargs finger
In your example, ssh user@servername
and user@servername1
are pretty similar. Just to be clear you didn't want to use those in the ssh command itself?:
while read user
do
ssh $user echo hi #ssh to each user/server in turn
done <text.txt
Upvotes: 0
Reputation: 1782
if you need to work with local file, not with remote copy, you can try to do next: call ssh
command in a different terminal, then you can continue to work locally and process you local file
xterm -e "bash -c \"ssh user@servername; exec bash\"" &
Upvotes: 0
Reputation: 247042
Try:
scp local_file user@servername:./remote_file
ssh user@servername cat -n remote_file
Upvotes: 2