I am having to put together a script that will ssh into devices to run a command such as "show running-config" and save the output to a file on my local machine. I have done similar tasks like this right from the command line and have it save the file to my local system. For example,
ssh firstname.lastname@example.org ls > ls_from_remotes_sys
And the file ls_from_remotes_sys is on my local system. However, I will need to script this and the only way I know how to do that is with expect. So I have put together this:
#!/usr/bin/expect -f spawn ssh email@example.com ls > ls_from_remotes_sys expect "firstname.lastname@example.org's password:" send "password\r" interact
The expect script works but the file gets saved to the remote system, which is not what I want.
Question 1 - Why does the file get saved to the local system from command line and why does it get saved to the remote system with expect?
Question 2 - Is there a way to send the file to my local system? (ssh back is not an option)
I was thinking that maybe instead of redirecting into a file I could just have the script output the command results to my screen. So,
Question 3 - If I do this, how can I capture the stdout on my screen from the remote system and send it to a file on the local system?