0

I want to create a script which i will use to generate some reports, but to do that i have to answer few questions, which being asked by other script i run (already located in destination server in /tmp)

The answers can be yes, no, for some questions i need to select 1,2 or 3, i some cases i need "Press [Enter] to continue:"... So my questions how to do it in the best way?

How do i ssh to destination servers (are located in file on source jump server and to which i have passworless connection to from jump server) like i do it in bash?

#!/bin/bash
while read LINE ; do
                ssh - $LINE <<"EOF"....

This is my script as of now, the order of the answers is: yes/yes/yes/ENTER/2/3/1/no/no/yes

#!/usr/bin/expect -f
spawn ssh ???????
send -- "/tmp/sort_hpux.sh\r"
expect "Would you like to run the data collector now? [y,n] (y)"
send -- "y\r"
expect "Directory '/var/VRTS/VRTSspt' does not exist. Do you want to create it? [y,n,q] (y)"
send -- "y\r"
expect "Press [Return] to indicate your acceptance of the terms and conditions as indicated in the /tmp/./sort/advanced/terms.txt file, or q to decline: (y)"
send -- "y\r"
expect "Press [Return] to continue:"
send -- "\r"
expect "Choose your option: [1-2,q] (1)"
send -- "2\r"
expect "Choose your option (separate multiple selections with commas): [1-5,b,q] (1,2,3)"
send -- "3\r"
expect "Choose your option: [1-3,b,q] (1)"
send -- "1\r"
expect "Do you want to create a sanitized report with no hostnames and IP addresses? [y,n,q] (n)"
send -- "n\r"
expect "Would you like to send SORT Data collector session logs to Veritas to help improve SORT Data collector in future? [y,n,q] (y)"
send -- "n\r"
expect "Your tasks are completed. Would you like to exit the data collector? [y,n,q] (y)"
send -- "y\r"

expect eof
Alxta13
  • 11
  • 4
  • Expect uses [Tcl](http://www.tcl.tk/doc/) which is another language you need to learn first. For example, `expect "Press [Return] to continue:"` would not work because `[...]` has [special meaning](http://www.tcl.tk/man/tcl8.7/TclCmd/Tcl.htm#M11) in Tcl. – sexpect - Expect for Shells Jul 21 '20 at 09:28
  • If you are more comfortable with shell syntax you can try my [sexpect (Expect for Shells)](https://github.com/clarkwang/sexpect). – sexpect - Expect for Shells Jul 21 '20 at 09:30

1 Answers1

1

Would this work? Often the best expect choice is to not use it at all.

printf "%s\n" yes yes yes "" 2 3 1 no no yes \
  | ssh host /tmp/sort_hpux.sh
glenn jackman
  • 238,783
  • 38
  • 220
  • 352