I have few queries in expect..

I'm using expect script and I need to pick the password from a different file..

1) I'm able to do it.. but for one of my connection the password starts with # (hash mark) hence its picked.. I use the below command

set pwfl [open "/tmp/test/m1"]
set pw [read "$pwfl"]

2) how to set the format for date in the log file.. I use the below.. [exec date]_log file.. but the date format alone needs to be changed

!/usr/bin/expect -f

set pwfl1 [open "/tmp/test/m2"] set pw1 [read "$pwfl1"] set pwfl3 [open "/tmp/test/m4"] set pw3 [read "$pwfl2"] log_file [exec date]_Ext_Push_FTP.log spawn sftp -v -o Port=122 -o IdentityFile=/tmp/test/SSH_PrivateKey_SFTPTesting.openssh -o PasswordAuthentication=yes t_rt_ext_push_sftppak_p@************ set timeout 15 expect "Enter passphrase for key '/tmp/test/SSH_PrivateKey_SFTPTesting.openssh':" {send "$pw3\r"} set timeout 30 expect "t_rt_ext_push_sftppak_p@e********'s password:" {puts "$pw1\r"} expect "sftp>" {send "put Sample_RT_Ext_Push_SFTPPAK.txt\r\n"} expect "sftp>" {send "!echo Test file has been uploaded successfully by whoami at date >> Ext_Push_SFTPPAK.ftp\r\n"} expect "sftp>" {send "bye\r"}

  1. I don't see you describing a problem. Is there an error?

  2. use expect's builtin timestamp command:

    set log_file [timestamp -format {%Y%m%d_log.file}]     ;# => 20170714_log.file
  • I'm more worried abt 1st question.. can you help me with that? – Arulanandam S Jul 14 '17 at 10:57
  • what is the question? You don't say what problem you have. – glenn jackman Jul 14 '17 at 11:01
  • I need to execute expect without showing password to others.. so I'm reading password from another file.. since the password start with # its not working – Arulanandam S Jul 14 '17 at 11:04
  • more details a.txt is file with password alone I need the expect to read the file for the password and then enter it.. but the password is starting with # – Arulanandam S Jul 14 '17 at 11:05
  • how to send ascii characters to expect file.. – Arulanandam S Jul 14 '17 at 11:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.