Problem with expect.


 
Thread Tools Search this Thread
Operating Systems AIX Problem with expect.
# 1  
Old 10-10-2008
Problem with expect.

Hi,
I am facing a strange problem while executing a script from a solaris server. This script calls another one to execute "expect" commands on some other 40 servers (all AIX 5200). I am passing username and password to the "expect" script as arguments. My problem is that it is showing the password when the script is logging in to some of these AIX servers, and the strange thing is this happens to different servers in different time (not on the same set of servers). I am invoking it in ksh. I am also using "stty -echo", but it does not show any effect here.
Can somebody suggest..?
This is how my script looks like..

Code:
#!/usr/local/bin/expect
set timeout 20
set servname [lindex $argv 0]
set uname [lindex $argv 1]
set password [lindex $argv 2]
spawn pbrun -h $servname root
expect "assword:"
send "$password\r"
expect "root#"
send "mkdir -p /tmp/qwho\r"
expect "root#"
send "hostname > /tmp/qwho/`date +%m-%d-%y`.`hostname`.log\r"
expect "root#"
send "-my command- >>/tmp/qwho/`date +%m-%d-%y`.`hostname`.log\r"
expect "root#"
send "scp /tmp/qwho/*.log $uname@-my serv name-:/tmp/DEC/QWHO/logs/\r"
expect "assword:"
send "$password\r"
expect "root#"
send "rm /tmp/qwho/*.log\r"
expect "root#"
close


Last edited by bakunin; 10-10-2008 at 08:09 AM.. Reason: Please use "code"-tags when posting code. Thx.
# 2  
Old 10-10-2008
Do you see the password (in the process list?) when logging into the target server or when scp'ing the logfile from target server back to source server?
# 3  
Old 10-12-2008
Thanks for the quick reply..
I am seeing the password while logging in to the target servers using expect. When I run the script, it shows me the job process. ie, doing "pbrun" then it shows the banner of the target machine, then the prompt and there it shows the password. doing scp it does not show password.
However I have another script which use expect only to do scp from certain machines. There it shows the password. I have tried using "echo -stty" and "spwn -noecho pbrun <server_name> root". It does not seem to be working..
# 4  
Old 10-13-2008
I think that you cannot prevent the password being visible in the processlist as long as you pass it over as an argument. In this case it was just a question of issuing the ps command at the right time to see it. This was about your current code:
Code:
#!/opt/freeware/bin/expect -f
stty -echo
set pass [lindex $argv 0]
sleep 1
send "$pass\r"

I named the script "te2" and used the little loop following to catch ps output while I ran the above script handing over "abc" as password:
Code:
(0)aserver:/home/shockneck> while true; do ps -fushockneck | grep [a]bc; done

During this one second sleep the loop catches the password more than ten times:
Code:
 shockneck 25470 15792   3 22:25:07  pts/0  0:00 /opt/freeware/bin/expect -f te2 abc
 shockneck 25470 15792   3 22:25:07  pts/0  0:00 /opt/freeware/bin/expect -f te2 abc
 shockneck 25470 15792   3 22:25:07  pts/0  0:00 /opt/freeware/bin/expect -f te2 abc
[...]
 shockneck 25470 15792   3 22:25:07  pts/0  0:00 /opt/freeware/bin/expect -f te2 abc
 shockneck 25470 15792   1 22:25:07  pts/0  0:00 /opt/freeware/bin/expect -f te2 abc

Then I rewrote your code to this:
Code:
#!/opt/freeware/bin/expect -f
stty -echo
send_user "password? "
expect_user -re "(.*)\n"
send_user "\n"
set pass $expect_out(1,string)
sleep 1
send "$pass\r"

This way the password does not show up in the ps output. So you might just adapt your script. HTH.
# 5  
Old 10-15-2008
hey thanks.. I shall try these..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash expect problem

Hey there :) I have a Bash Script and I'm trying to update Roundcube, but theres a user interactive line like: bin/installto.sh /var/www/mail/rc Upgrading from 1.1.3. Do you want to continue? (y/N) I'm trying to avoid this user interaction like this: cd roundcubemail-1.2.1 >/dev/null... (5 Replies)
Discussion started by: Aeris
5 Replies

2. Shell Programming and Scripting

Problem with expect script

expect { -re "(.*)NEXT PAGE(.*)" { send "\r\n" } exp_continue (0 Replies)
Discussion started by: sagar_1986
0 Replies

3. Shell Programming and Scripting

problem with expect

i have written simple expect script but it doesnt work the way that i want can someone suggest wat is the issue? #!/usr/bin/expect spawn ssh abc@abc expect "password:" send "xyz\r" expect "$" send "mkdir hello\r" #sleep 10 #exit 0 output --------------- it does not create directory... (4 Replies)
Discussion started by: bkumar82
4 Replies

4. Shell Programming and Scripting

expect script problem

Hi, Have strange problem. When I run an expect script towards a switch, it will not work. $ ./test2 spawn ssh admin@sesafdd101 Password: Last login: Thu Dec 25 13:20:54 2008 from 172.20.96.14 ECN430/330/212 Linux, based on Wind River Linux glibc_small (standard) 2.0 Trying... (1 Reply)
Discussion started by: etxnreg
1 Replies

5. UNIX for Dummies Questions & Answers

Problem in Expect

Hi Im writing an expect program for automating ftp. Having trouble with mget: expect "ftp>" {send "mget *.txt\r"} expect "mget*?" {send "n\r" ; expect_continue} expect "ftp>" {send "bye\r"} But expect even on ftp prompt "n" gets sent Please help... (1 Reply)
Discussion started by: crackle1985
1 Replies

6. Shell Programming and Scripting

expect problem

hi all, guys i have a problem in this code... any help ? #!/usr/bin/expect if { $argc != 3 } { puts "Usage:" puts "$argv0 username oldpwd newpwd" exit } #set machine set username set oldpwd set newpwd set completed_list " " (2 Replies)
Discussion started by: b1sh0p
2 Replies

7. Shell Programming and Scripting

sftp expect timeout problem

hello All, I am doing SFTP using expect. We just change our server from sun solaris 8 to sun solaris 10. The script was working good on sun solaris 8. But it is giving problem on 10. from shell, SFTP is working fine.Please help me. What can be the problem. LIB_sftp_get() { ... (0 Replies)
Discussion started by: mindtee_abhi
0 Replies

8. UNIX for Dummies Questions & Answers

Strange expect problem

Hi I'm writing a script which calls an expect script to retrieve configuration files for network devices. I want to avoid using TFTP to transfer the configs if possible and so I'm redirecting the screen output to a text file. This is the expect script: #!/usr/local/bin/expect set... (2 Replies)
Discussion started by: Ant1815
2 Replies

9. Shell Programming and Scripting

Expect script problem

Hello all you scripting Gurus, I have an expect script that gets called from an AppleScript Studio app that basically takes arguments for user name, password, and server address and then calls rsync. Everything works wonderfully, EXCEPT (there had to be one of those) if the user name starts... (4 Replies)
Discussion started by: jdyck
4 Replies

10. AIX

problem with expect eof

hi guys i have such simple script, which i'm executing on AIX 5.3 #!/usr/local/bin/expect spawn passwd exptest set password 123 expect "*password:*" send "$password\r" expect "*password again:*" send "$password\r" expect eof the output is following: spawn passwd exptest sh:... (4 Replies)
Discussion started by: zoom
4 Replies
Login or Register to Ask a Question