[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [K12OSN] Re: recommnedation for remote email retrieval



Michael Cortes wrote:

I have configured fetchmail for this one user via webmin. Webmin created .fetchmailrc in the user's home directory. I copied that file to another location and put the following in root's crontab:

*/3 * * * * /usr/bin/fetchmail -f /*path*/.fetchmailrc


nah, don't do it that way.. ;-)


Use the 'switch-user' command to run fetchmail as the users own UID. Like this..

# leave fetchmail -daemon running for these users
su steve -c "fetchmail -d 200"
su mavis -c "fetchmail -d 200"


To do this, you will have to have built them a fetchmail.conf file first. I would consider placing a commented-out fetchmail.conf in /etc/skel/
where you can leave users to sort it for themselves - add their POP3 Server *here* and then email the sysadmin blah - not too hard. Then just add another su <username> -c "fetchmail -d 200" to your rc.fetchmail, and call this script from rc.local or something..



After some google searching and man pages, I still could not figure out how to run fetchmail in daemon mode. So, it is now function for this user. However, I still am presented with two problems.


use fetchmail like $ fetchmail -d <seconds>


.. or

as root, spin off a process running fetchmail as that user -

# su <username> -c "fetchmail -d 200"

This will leave fetchmail running, in daemon mode, running non-root (UID of <username>), checking for mail, and collecting it every 200 seconds.



1. Can I get the results of the cronjob sent to a logfile (i.e. messages) instead of emailed to root?



Redirect the output of the script to a file, viz ;


# ./my_script 2> /var/log/my_script.errors > /var/log/my_script.output


There are *two* outputs from running a script, (or a binary) ;


stdout, which is the '> /var/log/my_script.output'

..and

stderror, which is the '2> /var/log/my_script.errors

You can redirect the output of either of these two streams anywhere you want, or even pipe them (use the | instead of the > ) to a binary.
Please be exceedingly careful with this as root, as you can easily make a mistake and over-write a critical system binary by redirecting to it, when you really meant 'pipe'.. Best to test as non root, and then, and when you are happy with it, chown the script to root, and place it in service. If have trashed a system entirely by doing this..



2. I can see where I might want to do this for more users. How would I employ fetchmail for more than one user?



as above, build a file something like rc.fetchmail, and put all your fetchmail users in this script, on their own line, viz,


#!/bin/bash
# /etc/rc.fetchmail
#
#
su steve -c "fetchmail -d 200"
su mavis -c "fetchmail -d 200"



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]