-   Linux - General (
-   -   using Expect command to automate prgms (

mehargags 06-14-2003 04:03 PM

using Expect command to automate prgms
I'll be greatful if Any of u Scriptor's there can help me out automating A program that i need to run on every start up. Its called 24online. i need to run 24OnlineClient -u <username> then press Enter then is asks for password then i need to type my password & then it logs in.
I heard "Expect"(a tcl application) can do that user intake kionda thing along witha combination of a "send" command.
the file is available at here

david_ross 06-14-2003 04:32 PM

Try creating a script "24connect"

#!/usr/bin/expect -f
spawn 24OnlineClient -u [lindex $argv 0]
set password [lindex $argv 1]

send "$password\r"
expect eof

Replace "LINE BEFORE PASSWORD" with the line that promts you for the password - eg "Enter your password: "

You can then call 24connect using:
24connect username password

mehargags 06-15-2003 05:28 AM

well i tried it but c'd not do it, probably i am very new to all this, Just a couple of quetions..
What does the "spawn" do.
i think i must tell u the Exact thing i do. I have copied the executable to /usr/bin.
at console i do this EXACTLY to make it login:-
# 24 -u GaganPaul (then press enter)
password: (asks password, put "cute" i.e. my passwd, enter)

it then logs in & to check i ping if ping is success i am logged into my gateway. Can u write me a Single file, doesnt need to have args as i can hardcode my username & pass(no security issues here) & just call it in the rc.d to autorun at start up

david_ross 06-15-2003 05:55 AM

It would help if you logged in manually and copied and pasted the output here (mask usernames and passwords - just so long as I know where they go). The reason for using arguments may be if you had 2 accounts etc - it is just for scalability.

mehargags 06-15-2003 05:42 PM

Well i made my procedure Clear iin the 2nd post. wot i can Post u is the text iin the xterm that u can figure out how the program behaves. I already told u my userrname & password. no prbems of security as noone on this world can use that usrername & password specific to my LAN
----xterm text goes here-----
root@scavan:~# 24 -u GaganPaul
no pls crefully see wot i tell u.
1. "24" is the binary i am running. -u is to give it username
2. "GaganPaul" is the username i pass to it & then press enter
3. asks for the password in next line
4. i put password "cute" there & press enter
5. no msg if login is Successful else it gives me "Try Again"
6. i ping just to check if i am conected to my gatewway. This prgm is a client for Cyberoam Server which runs on our Gateway server to authenticate the users on our LAN that share that gateway. we r on fixed Ip's. So when we login we need to run this program. only after we log in , we r given Access to internet. if u want better idea just downlad the binary from the Site mentioned above & have a look urself

david_ross 06-15-2003 05:52 PM

Sorry - missed that in your second post - I was probably doing too many things at once.
The script should probably be

#!/usr/bin/expect -f
spawn 24 -u GaganPaul

expect "password: "
send "cute\n"
expect eof

Note! The space after the : may/maynot exist.

mehargags 06-15-2003 06:00 PM

i tried it all but no luck it gives the following error
cb is the file i made ;)
bash-2.05b# chmod +x cb
bash-2.05b# ./cb
spawn 24 -u GaganPaul

remove: No such file or directory
sendto: Socket operation on non-socket
bash-2.05b# cute
bash: cute: command not found
when i say./cb it asks fpor the password exactly the way 24 does but when i put my password cute it displayes the error u can seee

just elaborate wot spawn does actually so i may be able to help myself a bit.

david_ross 06-15-2003 06:21 PM

Spawn just starts the progam.

From the example there you don't have a space after the : did you do as I suggested in my last post and try it without the space?

david_ross 06-15-2003 06:23 PM

I also didn't type password with a capital P.

The expect string must match the line where the input is to occur exactly.

mehargags 06-15-2003 08:16 PM

No man it doesnt want to Run i get the same Shit again. i had tried the space there already, ya but i missed out that Caps P. Still i made the Corrections & get :-
root@scavan:~/Desktop# ./cb
spawn 24 -u GaganPaul
remove: No such file or directory
sendto: Socket operation on non-socket

All times are GMT -5. The time now is 11:10 PM.