I'm new to scripting and need some help. I am creating an expect script that from a Linux server, that will automatically ssh/log
in to our HP StoreOnce Appliance
#!/usr/bin/expect -f
set password "password"
match_max 1000
spawn ssh -o StrictHostKeyChecking=no user@10.x.x.x
expect "*?assword:*"
send -- "$password\r"
send -- "\r"
interact
When executing this script, I was able to automatically login and from there I can type the commands.
Please see output below:
=================================================================
[root@dpis tmp]# ./test.exp
spawn ssh -o StrictHostKeyChecking=no user@10.x.x.x
Password:
Last login: Thu Jan 26 08:37:24 2017 from 10.x.x.x
Welcome to the HP StoreOnce Backup System Command Line Interface.
Type 'help' at the prompt for context-sensitive help.
>
But what I want to achieve is for the script to not only automatically log-in but also automatically put a command and show its output then exit.
I tried to add the following lines below after interact
expect ">"
send -- "serviceset show status"
Seeking assistance on how to achieve this? Thanks!
expect script.exp > /var/tmp/file.txt
) or use the expectlog_file
command. – glenn jackman Jan 27 '17 at 14:10