Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # This script runs fetchmail for every user who has a .fetchmailrc in his home folder
- # and whose home-folder is in /home (so not system accounts).
- # fetchmail is started as the user, so running this script as root isn't a problem.
- # I have it in my crontab to run every 5 minutes.
- # If a user already has a running fetchmail-instance, the user is skipped this time.
- for fetchmailrc in /home/*/.fetchmailrc
- do
- user=${fetchmailrc/\/home\/}
- user=${user/\/.fetchmailrc}
- ps=$(ps -u "$user" | grep fetchmail)
- if [ -z "$ps" ]
- then
- echo "Doing fetchmail for user '$user' ..."
- su -c "cd; fetchmail > .fetchmail.log" "$user"
- echo
- echo "Output of fetchmail:"
- cat "/home/$user/.fetchmail.log"
- else
- echo "fetchmail already running for user '$user'"
- echo "ps output: $ps"
- fi
- echo
- echo
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement