Easy BASH script question

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Easy BASH script question

Post 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
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 :?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

hmmm... perhaps something like this:

Code: Select all

echo `echo &quote;pAssWord&quote; | fetchmail -c -u user localhost`;
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 :)
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Cheers tim that's great.

I'll have another play :)
Post Reply