#!/usr/local/bin/expect -f # # This Expect script was generated by autoexpect on Fri Nov 16 12:29:38 2007 # Expect and autoexpect were both written by Don Libes, NIST. # # Note that autoexpect does not guarantee a working script. It # necessarily has to guess about certain things. Two reasons a script # might fail are: # # 1) timing - A surprising number of programs (rn, ksh, zsh, telnet, # etc.) and devices discard or ignore keystrokes that arrive "too # quickly" after prompts. If you find your new script hanging up at # one spot, try adding a short sleep just before the previous send. # Setting "force_conservative" to 1 (see below) makes Expect do this # automatically - pausing briefly before sending each character. This # pacifies every program I know of. The -c flag makes the script do # this in the first place. The -C flag allows you to define a # character to toggle this mode off and on. set force_conservative 0 ;# set to 1 to force conservative mode even if ;# script wasn't run conservatively originally if {$force_conservative} { set send_slow {1 .1} proc send {ignore arg} { sleep .1 exp_send -s -- $arg } } # # 2) differing output - Some programs produce different output each time # they run. The "date" command is an obvious example. Another is # ftp, if it produces throughput statistics at the end of a file # transfer. If this causes a problem, delete these patterns or replace # them with wildcards. An alternative is to use the -p flag (for # "prompt") which makes Expect only look for the last line of output # (i.e., the prompt). The -P flag allows you to define a character to # toggle this mode off and on. # # Read the man page for more info. # # -Don set timeout -1 spawn $env(SHELL) match_max 100000 expect -exact "\]0;root@yogi:/scripts\[root@yogi scripts\]# " send -- "ftp booboo\r" expect -exact "ftp booboo\r Connected to booboo.\r 220 (vsFTPd 1.2.1)\r 530 Please login with USER and PASS.\r 530 Please login with USER and PASS.\r KERBEROS_V4 rejected as an authentication type\r Name (booboo:root): " send -- "ftpadmin\r" expect -exact "ftpadmin\r 331 Please specify the password.\r Password:" send -- "abc1234\r" expect -exact "\r 230 Login successful.\r Remote system type is UNIX.\r Using binary mode to transfer files.\r ftp> " send -- "ls\r" expect -exact "ls\r 227 Entering Passive Mode (192,167,37,43,182,234)\r 150 Here comes the directory listing.\r -rw-r--r-- 1 4465 4465 29187 Sep 06 21:52 Linux_booboo_cronlistings.txt\r -rwxr-xr-x 1 4465 4465 1238 Sep 06 19:51 cron_capture\r -rwxr-xr-x 1 4465 4465 1230 Sep 06 20:23 cron_capture-LINUX\r -rw-r--r-- 1 0 0 84 Apr 03 2007 drinfo.sh\r -rw-rw-r-- 1 4465 4465 368535 Sep 07 20:40 get_AIX_sysinfo.log\r -rw-rw-r-- 1 4465 4465 205 Sep 07 15:48 get_dr_info.ksh\r -rw-rw-r-- 1 4465 4465 10933 Sep 07 20:35 get_sysinfo2.log\r -rw-r--r-- 1 0 0 666 Apr 03 2007 getall.sh\r -rw-r--r-- 1 0 0 256 Apr 03 2007 imp.sh\r -rw-r--r-- 1 0 0 323 Apr 03 2007 pb_getnet.sh\r -rw-r--r-- 1 0 0 167 Apr 03 2007 pb_getvg.sh\r -rw-r--r-- 1 0 0 618 Apr 03 2007 putall.sh\r -rw-r--r-- 1 0 0 10240 Sep 07 15:50 scripts.tar\r -rw-r--r-- 1 0 0 32 Apr 03 2007 um.sh\r 226 Directory send OK.\r ftp> " send -- "get getall.sh\r" expect -exact "get getall.sh\r local: getall.sh remote: getall.sh\r 227 Entering Passive Mode (192,168,37,43,52,152)\r 150 Opening BINARY mode data connection for getall.sh (666 bytes).\r 226 File send OK.\r 666 bytes received in 0.064 seconds (10 Kbytes/s)\r ftp> " send -- "bye\r" expect -exact "bye\r 221 Goodbye.\r \]0;root@yogi:/scripts\[root@yogi scripts\]# " send -- "" expect eof