Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

automating password change with expect...

Status
Not open for further replies.

InigoMontoya

IS-IT--Management
Jun 18, 2003
51
0
0
US
Sorry I don't mean to dump a whole block of code here but I've been trying to get this thing to work for a while now and It just keeps failing. I've narrowed it down to one last error but I can't quite figure it out. I'm hoping someone here can help.

What this section of the script is supposed to do is during a file transfer session it should be able to change the password automatically and store it in a file when prompted by the server.

I modified it a bit from when it failed and I have not tested it since. The last time it failed with a..

Code:
can not find channel named "file5" while executing "puts -nonewline $pfile $newpass"

I changed the variable named from $pfile to $pfile2 and added a new line..

Code:
set pfile2 [open $passfile w]

Perhaps I had to open the file for writing first. But this section seemed to have worked before w/out it.

If anyone has any ideas it would be greatly appreciated.

---------------------

Code:
expect {
        "expired" {
               set newpass [exec /usr/local/bin/mkpasswd -l 8 -c 6 -d 1 -s 1 -C 0]
                expect "$progy>" {
                        send -h "chpwd\r"
                }
                expect "Enter old Password:" {
                        send -h "$pass\r"
                }
                expect "Enter new Password:" {
                        send -h "$newpass\r"
                }
                expect "Re-Enter new Password:" {
                        send -h "$newpass\r"
                }
                expect "Virtual user * logged in" {
                        set pfile2 [open $passfile w]     # added this line
                        puts -nonewline $pfile2 $newpass
                        close $pfile2
                }
                passwd_changed "$name $newpass"
                expect "$progy>" {
                        send -h "ascii\r"
                }
                expect "Type changed to Ascii" {
                        send -h "lcd $localdir\r"
                }
                expect "Local directory now" {
                        send -h "put $uploadfile\r"
                } 
                expect "Transfer Complete" {
                        send -h "bye\r"
                }
                unset newpass
        }
        "Virtual user * logged in" {
                expect "$progy>" {
                        send -h "ascii\r"
                }
                expect "Type changed to Ascii" {
                        send -h "lcd $localdir\r"
                }
                expect "Local directory now" {
                        send -h "put $uploadfile\r"
                }
                expect "Transfer Complete" {
                        send -h "bye\r"
                }
        }
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top