Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello!
I am now working on a e-mail checking script, until now i have:
Code:
function mail ()
{
telnet mail.rdslink.ro 110
user $1
pass $2
list
grep '+OK POP3'
}
The purpose is to have 2 arguments $1 username and $2 password, the script should login on the given mail server and grep the line +OK POP3. The problem is i don't know how to i tell the computer to wait a short period of tine between the telnet 'line' and the user 'line' and the the login fails...
Any suggestions are welcomed.
Thanks!
UPDATE:
I have seen that actualy the script waits until the telnetl conetions is over and then uses the imput data as i cauld se using:
Code:
function mail ()
{
telnet mail.rdslink.ro 110
echo "user" $1
echo "pass" $2
list
grep '+OK POP3'
}
And i get:
Code:
root@MainThinkTank:~# mail bosharelu behlicuta
Trying 193.231.236.20...
Connected to mail.rdslink.ro.
Escape character is '^]'.
+OK Hello there.
exit
quit
Connection closed by foreign host.
user bosharelu
pass behlicuta
-bash: list: command not found
This probably means that there's no line that contains "+OK POP3", so grep doesn't return anything. Remove pipe and grep command, then have a look at the output.
function mail ()
{
telnet mail.rdslink.ro 110 << EOF
user $1
pass $2
list
EOF
}
I get:
Code:
root@MainThinkTank:~# mail bosharelu behlicuta
Trying 193.231.236.20...
Connected to mail.rdslink.ro.
Escape character is '^]'.
Connection closed by foreign host.
I really don't get it. How can i make this wayt and/or execute the 'user' and 'pass' commands...
You're right, it won't work that way. That's because the commands will be sent even before the remote server is ready to receive them. You'll have to use "expect":
Ok, that's ok, works just like it should. I have still some more stuff to ask:
1) The '>/dev/null' line makes 'grep' don't show? More precisely what does it do?
2) Where did you learn all that stuff ?
3) I have a problem, how can i make this little script echo "Login fail" when either the user or password are incorrect? There is nothing to 'grep' for....
1) The '>/dev/null' line makes 'grep' don't show? More precisely what does it do?
It directs the standard output of grep to /dev/null, and everything that's sent to /dev/null will be discarded.
Quote:
2) Where did you learl all that stuff ?
I learled that stuff (and still do) from the man pages, searching the web and trial&error. A good reference for general bash scripting is http://www.tldp.org/LDP/abs/html/.
Quote:
3) I have a problem, how can i make this little script echo "Login fail" when either the user or password are incorrect? There is nothing to 'grep' for....
You can do some more scripting in Expect, see "man expect". The following might work, for example:
send: spawn id exp6 not open
while executing
"send "quit""
I tried to 'gerp' for 'not open' and post an "Login failed" message but that didn't worked out..
I get some more errors and i'm confused becouse i don't really know what the exact commands do :P And i really have no time to look them up propperly, so much to do!
Code:
root@MainThinkTank:~# bmail a b
missing close-brace
while executing
"expect {
"+OK*\n" {send_user "$expect_out(0,string)"}
-gl "-ERR" {send_user "Username or password incorrect.\n"}
send "quit"
send "quit"
"
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.