I am trying to run a script remotely (from a bash script), but am having trouble getting the output to redirect locally, for analysis. Running the script is no problem with:
ssh -n -l "$user" "$host" '/home/user/script.sh $params'
However I am unable to capture the output of that script. I have tried the following:
results=$(ssh -n -l "$user" "$host" '/home/user/script.sh $params')
results=`ssh -n -l "$user" "$host" '/home/user/script.sh $params'`
ssh -n -l "$user" "$host" '/home/user/script.sh $params' | grep "what I'm looking for"
ssh -n -l "$user" "$host" '/home/user/script.sh $params' > results_file
Any ideas?
You can even do things like:
To make things simple, generate a pub/private key pair using ssh-keygen.
Copy the *.pub key to the remote host into ~/.ssh/authorized_keys, make sure
it’s chmod’d 600
Then you can do
ssh -i ~/.ssh/yourkey user@host.com … etc
And it won’t ask for a password either. (If your key pair is passwordless)..