I need to write a script that runs on a PC with Centos 7 and connects to another PC with Centos 7 using ssh, execute a console command, for example "ls -la" and save the output of it to a file to be able to later analyze that output.
I have written the following EXPECT script:
#!/usr/bin/expect -f set timeout 120 spawn ssh email@example.com expect "assword:" send "PASSWORD\r" expect "prompt#" sleep 5 puts "Executing ls -la" send "ls -la\r" sleep 10 puts "Executing ps -af" puts "ps -af\r" sleep 10 puts "Closing the ssh session\r" send "exit\r"
This script connects correctly through ssh to the machine with IP = 22.214.171.124 and displays on the screen the messages that appears on "puts": Executing ls -la Executing ps -af Closing the ssh session
However, it does not show the result of executing the commands I send with send:
ls -la ps -af
What is wrong with this script?
How can I make the output of the previous commands saved in a file to be able to analyze it later with a bash script or a C program?