#! /usr/local/bin/expect # This script is used for retrieving the JEM-X Instrument Station # data from ISDC to DNSC by ftp. # # Prepared by Søren Brandt, sb@spacecenter.dk Aug 2004 # # The procedure is to log into ISDC by slogin, go to the directory # where data are stored and then do ftp to DNSC # The script will prompt for the password to ISDC and DNSC. # The files specified to be ftp'ed will be moved to a subdirectory # named "sent" as a backup in case the ftp for some reason was # unsuccessful # # ______________________________________________________________ # Usage: expect [name_of_this_script] [filemask] # # The script will retrieve all files in the ISDC directory of # the form [filemask]*.IPF # So if filemask is set to 0408 the script will retrieve all # IPF files from Aug 2004 # Providing no filemask will retrieve all files of the form *.IPF # # ______________________________________________________________ # # NOTE: ________________________________________________________ # Please costumize the script to use the appropriate user ID's # for the login accounts to be used at ISDC and DNSC contained # in the parameters ISDCuser and DNSCuser below. # The directories used at ISDC and DNSC for the data are # configured in the parameters ISDC_IPFdir and DNSC_IPFdir # # The userID's selected must must have the appropriate permissions # in the relevant subdirectories at ISDC and DNSC # _______________________________________________________________ # # define the user ID's at ISDC and DNSC # set ISDCuser "westerga" set DNSCuser "njw" # # define the data directories at ISD and DNSC # set ISDC_IPFdir "/unsaved_data/jemx/ipf" set DNSC_IPFdir "/r6/jemx/ISDC" # proc getpass {prompt} { set sttyOld [stty -echo raw] send_user $prompt set timeout -1 set passwd "" expect { -re "\r" { send_user \r\n } -re "\010|\177" { if {[string length $passwd] > 0} { # not all ttys support destructive spaces send "\010 \010" regexp (.*). $passwd x passwd } exp_continue } -re . { send_user * append passwd $expect_out(0,string) exp_continue } } eval stty $sttyOld return $passwd } # # This Expect script was generated by autoexpect on Wed Jul 21 12:42:26 2004 # 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 password1 [getpass "Please enter ISDC password for $ISDCuser:"] set password2 [getpass "Please enter DNSC password for $DNSCuser:"] set files [lindex $argv 0] set timeout -1 set send_slow {1 .1} spawn $env(SHELL) match_max 100000 sleep .1 send -s -- "slogin -l $ISDCuser isdcsf2.unige.ch\r" expect -exact "@isdcsf2.unige.ch's password: " sleep .1 send -s -- "$password1\r" expect "isdcsf2:*> " sleep .1 send -s -- "cd $ISDC_IPFdir\r" expect "isdcsf2:ipf*> " sleep .1 send -s -- "ls\r" expect "isdcsf2:ipf*> " sleep .1 send -s -- "ftp uhuru.spacecenter.dk\r" expect -exact "Name (uhuru.spacecenter.dk:$ISDCuser): " sleep .1 send -s -- "$DNSCuser\r" expect -exact "Password:" sleep .1 send -s -- "$password2\r" expect -exact "ftp> " sleep .1 send -s -- "cd $DNSC_IPFdir\r" expect -exact "ftp> " sleep .1 send -s -- "bin\r" expect -exact "ftp> " sleep .1 send -s -- "prompt off\r" expect -exact "ftp> " sleep .1 send -s -- "mput $files*.IPF\r" expect -exact "ftp> " sleep .1 send -s -- "quit\r" expect "isdcsf2:ipf*> " sleep .1 send -s -- "mv -f $files*.IPF sent/.\r" expect ":ipf*> " sleep .5 send -s -- "exit\r" sleep .5 send "exit\r" sleep .5 send_user "The following files were transferred:\n" send_user "$files\n" send_user "END OF AUTOMATIC IPF TRANSFER\n" expect eof