using expect to switch users in a script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting using expect to switch users in a script
# 1  
Old 10-03-2012
using expect to switch users in a script

hi, I need to switch users in a script
I'm newbee to expect
I wrote two files

1 sudo.exp, since su4098 is used as root in my laptop
Code:
#!/usr/bin/expect
spawn su su4098
expect *Password:*
send mypsw\n
interact

2 test.sh
Code:
ls
./sudo.exp
tcpdump -i wlan0 
su esolve
ls

however, in test.sh
when it switches to su4098,namely the root
it stops a while
and tens of seconds later, it run the password as a command
and the following commands: tcpdump, su esolve, and ls are not run

what is wrong with my scripts?
thanks!
# 2  
Old 10-04-2012
Try running it manually under "autoexpect", and see/generalize the script it writes.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Ubuntu

Expect /bash, 2 ssh login users

HI all i need to connect to about 900 cisco routers and switch to do some configs changes. the issue i am having is that half the devices have one set of username and password and the other half have another username and password. From expect or bash script i can ssh into a device and make... (1 Reply)
Discussion started by: quintin
1 Replies

2. Programming

Expect script returning string following a found expect.

I'm fairly new to scripting so this might not be possible. I am using Expect with Cisco switches and need to capture the string after finding the expect request. For example, when I issue "show version" on a Nexus switch, I'm looking to capture the current firmware version: #show version ... (0 Replies)
Discussion started by: IBGaryA
0 Replies

3. Shell Programming and Scripting

How to create multiple users using expect.?

Hi, guys. I need help on some expect problem. #!/usr/bin/expect set user set password set newuser spawn telnet x.x.x.x expect login* send “root\r” expect Password* send “123546\r” send "useradd $newuser\r" send "exit\r" interact I can add 1 user using expect script, but how do I... (1 Reply)
Discussion started by: alhazerd
1 Replies

4. UNIX for Dummies Questions & Answers

Not able to switch to other users using su -user from root

Hi all, I have a small problem. When I log in as root and try to switch to any other user using su -user, then it is giving an error saying libncurses.so permission denied. Can you help me? Thank you in advance. Sai. (1 Reply)
Discussion started by: sai2krishna
1 Replies

5. Red Hat

users cannot switch with "su" to another users

Hi, i have a problem, itīs because users without belonging wheel group cannot switch to another user , when the password is introduced says not right password. The only solution for now is to add them to wheel users, but then i have another problem, they can login as root. Is there any... (3 Replies)
Discussion started by: pabloli150
3 Replies

6. Shell Programming and Scripting

Switch to different user without expect

Hi, I have to switch to a different user and execute certain commands and then come back to the original user Ex: My id is 'usstage'. I need to switch to 'apstage', souce a script there, execute a function and then get back again to usstage. Please note that I do not have expect installed... (4 Replies)
Discussion started by: sugan
4 Replies

7. Shell Programming and Scripting

Need help with Expect script for Cisco IPS Sensors, Expect sleep and quoting

This Expect script provides expect with a list of IP addresses to Cisco IPS sensors and commands to configure Cisco IPS sensors. The user, password, IP addresses, prompt regex, etc. have been anonymized. In general this script will log into the sensors and send commands successfully but there are... (1 Reply)
Discussion started by: genewolfe
1 Replies

8. Shell Programming and Scripting

Expect help/interaction with switch..

Hi All, I have been trying to get an Expect program to communicate with a Remote Power Switch which will eventually log in, and then turn on/off certain outlets. For some reason, I can't get through the log in procedure with this Switch. When you first spawn the telnet, you get the Switch... (1 Reply)
Discussion started by: mrjgs70
1 Replies

9. UNIX for Dummies Questions & Answers

Expect command to switch user

Hi I have written a script to switch user and do some operations. I used expect command it doesn't work. It switches the user and waits for the Password to be entered manually. Also, i tried to fetch the pasword from passwd file, it didn't work.The script is as below: ... (4 Replies)
Discussion started by: Sapna_Sai
4 Replies

10. Shell Programming and Scripting

strange expect script behavior, or am i misunderstanding expect scripting?

Hello to all...this is my first post (so please go easy). :) I feel pretty solid at expect scripting, but I'm running into an issue that I'm not able to wrap my head around. I wrote a script that is a little advanced for logging into a remote Linux machine and changing text in a file using sed.... (2 Replies)
Discussion started by: v1k0d3n
2 Replies
Login or Register to Ask a Question