LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 06-14-2003, 03:03 PM   #1
mehargags
Member
 
Registered: Jul 2002
Distribution: Slackware
Posts: 66

Rep: Reputation: 15
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 Sourceforge.net here http://sourceforge.net/projects/cyberoam
 
Old 06-14-2003, 03:32 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
Try creating a script "24connect"
Code:
#!/usr/bin/expect -f
spawn 24OnlineClient -u [lindex $argv 0]
set password [lindex $argv 1]

expect "LINE BEFORE PASSWORD: "
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
 
Old 06-15-2003, 04:28 AM   #3
mehargags
Member
 
Registered: Jul 2002
Distribution: Slackware
Posts: 66

Original Poster
Rep: Reputation: 15
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 yahoo.com. 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
 
Old 06-15-2003, 04:55 AM   #4
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
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.
 
Old 06-15-2003, 04:42 PM   #5
mehargags
Member
 
Registered: Jul 2002
Distribution: Slackware
Posts: 66

Original Poster
Rep: Reputation: 15
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
Password:
root@scavan:~#
--------------------------------------
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
-----------extra------------
5. no msg if login is Successful else it gives me "Try Again"
6. i ping yahoo.com 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
 
Old 06-15-2003, 04:52 PM   #6
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
Sorry - missed that in your second post - I was probably doing too many things at once.
The script should probably be
Code:
#!/usr/bin/expect -f
spawn 24 -u GaganPaul

expect "password: "
send "cute\n"
expect eof
Note! The space after the : may/maynot exist.
 
Old 06-15-2003, 05:00 PM   #7
mehargags
Member
 
Registered: Jul 2002
Distribution: Slackware
Posts: 66

Original Poster
Rep: Reputation: 15
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
Password:cute

remove: No such file or directory
sendto: Socket operation on non-socket
bash-2.05b# cute
bash: cute: command not found
bash-2.05b#
------------------------------------------------------
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.
thx
 
Old 06-15-2003, 05:21 PM   #8
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
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?
 
Old 06-15-2003, 05:23 PM   #9
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
I also didn't type password with a capital P.

The expect string must match the line where the input is to occur exactly.
 
Old 06-15-2003, 07:16 PM   #10
mehargags
Member
 
Registered: Jul 2002
Distribution: Slackware
Posts: 66

Original Poster
Rep: Reputation: 15
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
Password:
remove: No such file or directory
sendto: Socket operation on non-socket
root@scavan:~/Desktop#
------------
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
using rpm to install of prgms lbooker Linux - Newbie 2 03-27-2005 10:04 AM
CGI script problem: Send/Expect command echo on webpage rajatgarg Programming 2 07-11-2004 04:38 PM
How would I automate this? onewhoknows Linux - Newbie 5 06-22-2004 04:49 AM
Automate Gnome/X applications - X-Expect? Flibble Linux - Software 0 02-16-2004 03:28 AM
xaw tv problem ,help me to watch my tv prgms in full screen rajeshkgk Linux - Software 1 10-15-2003 04:38 PM


All times are GMT -5. The time now is 07:06 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration