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

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 -f
set timeout 120
spawn ssh root@129.0.0.10
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 = 129.0.0.10 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?


Viewing all articles
Browse latest Browse all 158

Latest Images

Trending Articles



Latest Images

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