Page 1 of 1

Easy BASH script question

Posted: Mon May 23, 2005 4:55 pm
by Chris Corbyn
Hi all,

Quite new to BASH scripting but I'm sure this is obvious to some.

Code: Select all

echo &quote;... `fetchmail -c -u myusername localhost`&quote;
That will run and ask me for my password. Well the thing is, I wanna put it in .profile so it runs when I log in, without being prompted for a password. Can I somehow (pipe or whatever) put the password in the BASH script itself?

Cheers :D

Posted: Tue May 24, 2005 5:02 am
by Chris Corbyn
Never mind I just wrote a PHP CLI script that does it better anyway with a splash of ANSI color.

Still curious if you can do what I wanted with BASH though :?

Posted: Tue May 24, 2005 5:14 am
by Weirdan
hmmm... perhaps something like this:

Code: Select all

echo `echo &quote;pAssWord&quote; | fetchmail -c -u user localhost`;

Posted: Tue May 24, 2005 12:26 pm
by Chris Corbyn
Yeah i tried that but it gives error "Fetchmail: password not supplied" or something to that effect - it wont prompt for P/W that way but on the same token it doesnt read one.

Well I've realised how cool you make some PHP apps for CLI as a result anyway, playing with the ANSI settings to beautify things a bit.

Thanks anyway :)

Posted: Tue May 24, 2005 3:55 pm
by pickle
MySQL allows you to pass the password command line-wise using the -p[password immediately after] flag

ie:

Code: Select all

mysql -u root -pmyrootpassword
fetchmail might work the same

Posted: Wed May 25, 2005 3:20 am
by timvw
This is how my .fetchmailrc file looks like

Code: Select all

# scarlet accounts 
poll pop.scarlet.be with proto pop3
        user &quote;euki&quote; with password &quote;xxxxxxx&quote; is &quote;timvw&quote; here
        user &quote;vwadsl&quote; with password &quote;xxxxxx&quote; is &quote;timvw&quote; here
        user &quote;aardbei&quote; with password &quote;xxxxxx&quote; is &quote;timvw&quote; here
        user &quote;mv076639&quote; with password &quote;xxxxx&quote; is &quote;timvw&quote; here
        options fetchall

# khleuven accounts
poll mail.student.khleuven.be with proto imap
    user &quote;0040516&quote; with password &quote;xxxxxx&quote; is &quote;timvw&quote; here
    options fetchall ssl
This way, you only need to type "fetchmail" without entering a password.
Or you can run it in daemon mode: fetchmail -d 1800
(mail will be retrieved every 1800 seconds = 30 minutes)

So you can add something like "/usr/bin/fetchmail -d 1800" to your .profile or .bashrc or whatever :)

Currently i have the following in my cron file (to make sure the fetchmail daemon is started when the machine is booted...)

Code: Select all

@reboot                 /usr/bin/fetchmail -d 1800

Posted: Wed May 25, 2005 6:18 am
by Chris Corbyn
Cheers tim that's great.

I'll have another play :)