LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-11-2006, 03:22 AM   #16
Braynid
Member
 
Registered: May 2006
Location: Romania
Distribution: CentOS
Posts: 140

Original Poster
Rep: Reputation: 15

With:
Code:
send "pass $PASSWORD\n"
expect {
  "+OK*\n"      {send_user "$expect_out(0,string)"}
  -gl "-ERR"    {send_user "Username or password incorrect.\n"}
}
I get:
Code:
root@MainThinkTank:~# bmail a b
send: spawn id exp6 not open
    while executing
"send "quit""
In other words, what i want do to is echo "User/pass invalid" if the expect "+OK" afer 'pass $pass' fails. But if the pass is invalid the 'expect "+OK"' fails and the script returns error message. Another thing, how can i use a line like:
Code:
/usr/bin/expect <<EOF | grep '+OK logged in.' >/dev/null && echo "User/pass corecte pe domeniu" | grep 'Connection closed by foreign host.' >/dev/null && echo "User/pass INCORECTE pe domeniu"
Thanks.
 
Old 07-11-2006, 03:44 AM   #17
spirit receiver
Member
 
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424

Rep: Reputation: 33
I don't know where that error message comes from, remove "log_user 0" from the script to see what's going on. As for the "other thing", that line doesn't make much sense. Use the send_user commands to modify the script's output.
 
Old 07-11-2006, 03:56 AM   #18
Braynid
Member
 
Registered: May 2006
Location: Romania
Distribution: CentOS
Posts: 140

Original Poster
Rep: Reputation: 15
I have no "log_user 0" in my script
So here's what i want to do:
1) telnet to host.com
2) send user $user
3) send pass $pass
if (user/pass correct) I) TRUE echo "User/pass correct"
II) FALSE echo "User/pass incorrect"

So how do i do that?

I'm now reading some information on expect but i really love some support, thanks for all the kind information you already give me.

P.S: The 'send_user' writes nothing on the screen.

Last edited by Braynid; 07-11-2006 at 04:37 AM.
 
Old 07-11-2006, 05:09 AM   #19
spirit receiver
Member
 
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424

Rep: Reputation: 33
That's strange, my last script should do precisely what you're asking for (except that its output looks a little different). Below you'll find that script's output with false user/password, once with "log_user 0" and then with "log_user 1". The send_user output is marked red, Expect's regular output is green.
Code:
ada@barnabas:~/tmp> ./test nobody unknown
Connection established.
Username or password incorrect.
ada@barnabas:~/tmp> sed -i 's/log_user 0/log_user 1/' test
ada@barnabas:~/tmp> ./test nobody unknown
spawn /usr/bin/telnet pop.gmx.net 110
Trying 213.165.64.22...
Connected to pop.gmx.net.
Escape character is '^]'.
+OK GMX POP3 StreamProxy ready <32227.1152611652@mp041>
Connection established.
user nobody
+OK May I have your password, please?
pass unknown
-ERR Username or password incorrect.
Username or password incorrect.
 
Old 07-11-2006, 06:42 AM   #20
Braynid
Member
 
Registered: May 2006
Location: Romania
Distribution: CentOS
Posts: 140

Original Poster
Rep: Reputation: 15
Ok, i was trying to run it with 'function' in .bashrc !
I have added the following script in a separate file:
Code:
#! /bin/bash

LOGIN=$1
PASSWORD=$2

/usr/bin/expect <<EOF

log_user 0

spawn /usr/bin/telnet mail.rdslink.ro 110
expect {
  "+OK"         {send_user "Connection established.\n"}
  timeout       {send_user "Timeout.\n"; exit 1}
}

send "user $LOGIN\n"
expect {
  timeout       {send_user "Timeout.\n"; exit 1}
  "+OK"
}

send "pass $PASSWORD\n"
expect {
  "+OK*\n"      {send_user "\$expect_out(0,string)"}
      -gl "Connection closed by foreign host."    {send_user "Username or password incorrect.\n"}
}

send "quit"
EOF
Thanks for all the hints!!
Have a nice day!
 
Old 07-11-2006, 07:27 AM   #21
spirit receiver
Member
 
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424

Rep: Reputation: 33
Quote:
Originally Posted by Braynid
Ok, i was trying to run it with 'function' in .bashrc !
That should still work. I just tried, and it gives the same result.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shel script mail send ("/" in mail address) problem anaid Linux - Networking 3 08-23-2005 07:41 AM
shell script and mail ntan81 Programming 4 10-29-2004 03:55 PM
CGI Script runs to send mail, but mail is never sent robertwo Linux - Newbie 2 06-10-2004 09:57 AM
mail script doesn't run wedgeworth Linux - Software 0 10-15-2003 01:02 PM
E-Mail notification to users via SMS (gateway script ok, but notification script?!?) Riku2015 Linux - Networking 10 03-08-2002 10:16 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:15 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration