Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Want something in PERL

  1. #1
    Senior Member gore's Avatar
    Join Date
    Oct 2002
    Location
    Michigan
    Posts
    7,177

    Want something in PERL

    OK, here is what I'm trying to do:

    I want to make PERL call up Fetchmail, which is easy enough with system, but can I make it type in a password for me as well? The only book I have as of yet is "Learning PERL" and I'm searching right now for a way to do this, I got passed the first chapter and then on to chapter like, 15 or so, I skipped ahead because the begining stuff bored me and I was able to figure a lot of it out on my own anyway but can this be done? I'd just like to be able to execute a PERL script to check my mail and then of course I can do **** from there.

  2. #2
    Senior Member
    Join Date
    Dec 2004
    Posts
    3,171
    Hi gore,

    Does this help?...

    http://www.linux-sec.net/Mail/etc.ma...dmail_etc.html
    Linux security: mail, sendmail, fetchmail, procmail...

    http://www.catb.org/~esr/fetchmail/fetchmail-FAQ.html
    The Fetchmail FAQ


    Eg

  3. #3
    Senior Member gore's Avatar
    Join Date
    Oct 2002
    Location
    Michigan
    Posts
    7,177
    Sort of, but the way that would be helpful is if I could maybe tell the script to wait a few seconds as fetchmail loads, and then print my pass and seem to hit enter.

    Very new to coding and want to see what I can really make it do. The only limitations are those I set on me.

  4. #4
    Senior Member
    Join Date
    Dec 2004
    Posts
    3,171
    Hi gore,

    Then how about these?...

    http://lists.ccil.org/pipermail/fetc...er/006853.html
    [fetchmail] perl alternative for --configdump

    http://lists.ccil.org/pipermail/fetc...ly/008935.html
    [fetchmail]Re: mail to a perl script

    best I can come up with.

    Eg

  5. #5
    Just Another Geek
    Join Date
    Jul 2002
    Location
    Rotterdam, Netherlands
    Posts
    3,401
    I'm not sure if this will work but you could try something like:

    Code:
    open( FM, "| fetchmail") ;
    print FM "mypassword";
    close(FM);
    Another option would be to use the Expect::Simple module.
    Oliver's Law:
    Experience is something you don't get until just after you need it.

  6. #6
    Senior Member
    Join Date
    Mar 2004
    Posts
    557
    Hi

    As so often, there is not much left to say after SirDice

    Nevertheless, I would go with expect. It is rather useful
    to script, and, as mentioned, there is also a Perl module.

    The two versions look as follows:

    The "shell" version:

    Code:
    #!/usr/bin/expect
    
    #more info: man expect
    
    spawn fetchmail -u username mail.server.com
    expect "mail.server.com:"
    send "password\r"
    expect eof
    or with the Perl-module:

    Code:
    #!/usr/bin/perl
    
    use Expect;
    
    #more info: man Expect
    
    $handle=Expect->spawn("fetchmail -u username mail.server.com")
      or die "error while spawning\n";
    
    $handle->expect(5,"mail.server.com:"); #wait 5 secs at max
    $handle->send("password\n");
    
    $handle->soft_close();
    $handle->hard_close();
    In both versions, you could pass the password as a command
    line argument.

    Cheers.
    If the only tool you have is a hammer, you tend to see every problem as a nail.
    (Abraham Maslow, Psychologist, 1908-70)

  7. #7
    Senior Member gore's Avatar
    Join Date
    Oct 2002
    Location
    Michigan
    Posts
    7,177
    Dude sweet thanks!!!!!

  8. #8
    First, as for reading learning perl. Read the entire book from cover to cover, and then when you are done read it again. Once you are done with that. Pick up the Perl Cookbook, read that about 5 times. Then look for Programming in Perl. Once you are done with all of those, you question will seem to disappear.

    Next, Learning perl won't explain to you how to do what you want to do. It is kind of out of the grasp of the book. Great book though, one of my favorites.

    Next, I might be wrong when I say this, but SirDice, I am almost positive that you can't print a password to have it work. Kind of like trying to write a script to log-in with su. It won't work, now if the module you said works, I don't know. I am really crappy at using modules, I usually try to write everything myself.

    Gore there is also a sleep function in perl.

    sleep 60; I believe would work. It is based on seconds.

  9. #9
    Elite Hacker
    Join Date
    Mar 2003
    Posts
    1,407
    geez TT. The closest I've ever gotten to reading a programming book cover to cover was
    reading about 100 pages out of a 600 page book. Other than that I've never really read
    any programming books. In my opinion you have to be applying what you read as you
    are learning it. You can't read a book cover to cover and just go do everything it taught you.
    If you can I admire you. I know you said to read them a few times, but who in their right mind
    would do that? Maybe that's why my coding style sucks so bad . Oh well. I consider myself
    a decent programmer and I owe most of it to classes. If you can read a book and learn that way
    more power to you. Peace.

  10. #10
    Senior Member gore's Avatar
    Join Date
    Oct 2002
    Location
    Michigan
    Posts
    7,177
    Thanks, WK2300, I tried to greeny you but I gave out to many today, probably for the help I got in this thread, I was looking for something along the lines of the sleep thing you said to do and as you rightly pointed out it was no where in that book. I've been going to online docs as well to pick up new things.

    LOL, writing from reading is possible, Richard Stallman, before he owned a computer, wrote programs on paper and a few months after he got a computer he designed his own.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •