Mail script
Hello!
I am now working on a e-mail checking script, until now i have: Code:
function mail () 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 () Code:
root@MainThinkTank:~# mail bosharelu behlicuta |
Try this:
Code:
telnet mail.rdslink.ro 110 << EOF | grep '+OK POP3' |
Thanks spirit receiver!
With: Code:
function bmail () Code:
root@MainThinkTank:~# bmail Code:
root@MainThinkTank:~# bmail user pass I have tried some other stuff but didn't worked out... |
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.
|
With:
Code:
function mail () Code:
root@MainThinkTank:~# mail bosharelu behlicuta |
Try it with netcat instead of telnet: replace the word 'telnet' in your script with 'nc'.
|
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":
Code:
#! /bin/bash |
Thanks spirit receiver, i have modified that a bit and it works like a charm!
Thanks a lot guys for all the support! |
Actually, netcat (which is called "netcat" here instead of "nc") is much less awkward. Thanks, Berhanie.
|
Ok so now my script is:
Code:
function mail () |
Code:
grep "+OK logged in." >/dev/null && echo "login ok" |
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.... |
Quote:
Quote:
Quote:
Code:
#! /bin/bash |
Usig the script you provided i get:
Code:
send: spawn id exp6 not open 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 |
Seems like you forgot a closing brace, namely the one before 'send "quit"'.
|
With:
Code:
send "pass $PASSWORD\n" Code:
root@MainThinkTank:~# bmail a b 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" |
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.
|
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. |
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 |
Ok, i was trying to run it with 'function' in .bashrc !
I have added the following script in a separate file: Code:
#! /bin/bash Have a nice day! |
Quote:
|
All times are GMT -5. The time now is 06:50 PM. |