Quantcast
Channel: Active questions tagged expect - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 157

Expect script connects with ssh but does not run commands

$
0
0

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?


Viewing all articles
Browse latest Browse all 157

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>