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:
ssh_connection.exp :
#!/usr/bin/expect -fset timeout 120spawn ssh root@129.0.0.10expect "assword:"send "PASSWORD\r"expect "prompt#"sleep 5puts "Executing ls -la"send "ls -la\r"sleep 10puts "Executing ps -af"puts "ps -af\r"sleep 10puts "Closing the ssh session\r"send "exit\r"
This script connects correctly through ssh to the machine with IP = 129.0.0.10and displays on the screen the messages that appears on "puts":Executing ls -laExecuting ps -afClosing the ssh session
However, it does not show the result of executing the commands I send with send:
ls -laps -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?