LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1787|回复: 13

如何让fetchmail自启动

[复制链接]
发表于 2005-11-17 21:43:58 | 显示全部楼层 |阅读模式
现在想fetchmail在用户登陆后就自动启动,如是在~/.fetchmailrc里加入了
set daemon 60
这样fetchmail运行就会每隔60秒下载邮件
但是这样需要每次用户登陆之后键入 fetchmail命令,如何不键入这个命令
让fetchmail随用户登陆自动启动
 楼主| 发表于 2005-11-18 12:01:42 | 显示全部楼层
怎么没人知道,知道的快回答
回复 支持 反对

使用道具 举报

发表于 2005-11-18 12:39:58 | 显示全部楼层
用cron就可以了
回复 支持 反对

使用道具 举报

发表于 2005-11-18 12:55:29 | 显示全部楼层
在 rcX.d/下创建 fetchmail 的链接
回复 支持 反对

使用道具 举报

发表于 2005-11-18 13:16:20 | 显示全部楼层
cron?
加入~/.bash_profile。
楼主的语气很冲。
回复 支持 反对

使用道具 举报

发表于 2005-11-18 13:22:40 | 显示全部楼层
rcX.d/中不行
.bashrc里可以吗?
.bash_profile怎么设置?
回复 支持 反对

使用道具 举报

发表于 2005-11-18 13:44:31 | 显示全部楼层
bashrc 中加入
! ps aux | grep -q fetchmai[l] && fetchmail &

rcX.d 中为什么不行?
fetchmail 会为 HOME 下有 .fetchmailrc 文件的所有用户收取信件
回复 支持 反对

使用道具 举报

发表于 2005-11-18 13:54:42 | 显示全部楼层
我曾在/etc/init.d/中建了一个子localerc
内容如下:

  1. #!/bin/sh

  2. /usr/bin/fetchmail -f /home/skald/.fetchmailrc &

复制代码


Then

  1. ln -s localerc /etc/rc2.d/localerc
复制代码

然后开机最后一条显示必须用某个用户身份来运行fetchmail
我看了一下init.d/fetchmail里的配置
好像用的是fetchmail用户来启动fetchmail的
估计在那里修改差不多
不过我不会
不过在.bashrc里加入也只能在用户登陆后才能运行fetchmail
如果想开机把fetchmail做为一个进程以某个user的身份运行我还是没搞懂怎么搞
回复 支持 反对

使用道具 举报

发表于 2005-11-18 17:43:50 | 显示全部楼层
在 rcX.d 中 ln -s ../init.d/fetchmail S90fetchmail 不行么?
回复 支持 反对

使用道具 举报

发表于 2005-11-18 18:49:01 | 显示全部楼层
看了这个脚本的说明
个人觉得不行
/etc/init.d/fetchmail

  1. #!/bin/sh
  2. #
  3. # Fetchmail init script
  4. # Latest change: Do Jun 23 16:59:08 CEST 2005
  5. #
  6. # A fetchmailrc file containg hosts and passwords for all local users should be
  7. # placed in /etc/fetchmailrc.  Remember to make the /etc/fetchmailrc mode 600
  8. # to avoid disclosing the users' passwords.
  9. #
  10. # This script will NOT start or stop fetchmail if the /etc/fetchmailrc file
  11. # does not exist.
  12. #

  13. set -e

  14. if [ ! -e /etc/fetchmailrc ]; then
  15.     exit 0
  16. fi
  17. # Defaults
  18. PATH=/sbin:/bin:/usr/sbin:/usr/bin
  19. DAEMON=/usr/bin/fetchmail
  20. USER=fetchmail

  21. CONFFILE=/etc/fetchmailrc
  22. OPTIONS="-f $CONFFILE"
  23. PIDFILE="`getent passwd $USER | awk -F: '{ print $6 }'`/.fetchmail.pid"
  24. UIDL=/var/mail/.fetchmail-UIDL-cache

  25. test -f $DAEMON || exit 0
  26. if [ "$1" = "start" ]; then
  27.     if [ ! -r $CONFFILE ] ; then
  28.         echo "$CONFFILE not found."
  29.         echo "can not start fetchmail daemon... consider disabling the script"
  30.         exit 0
  31.     fi
  32. fi



  33. # sanity checks (saves on MY sanity :-P )
  34. if ! id $USER >/dev/null 2>&1; then
  35.         if [ "$USER" = "fetchmail" ]; then
  36.                 # The fetchmail user might have been removed when the fetchmail-common
  37.                 # package is purged. We have to re-add it here so the system-wide
  38.                 # daemon will run.

  39.                 adduser --system --ingroup nogroup --home /var/run/fetchmail \
  40.                         --shell /bin/sh --disabled-password fetchmail >/dev/null 2>&1 || true
  41.                 # work around possible adduser bug, see #119366
  42.                 [ -d /var/run/fetchmail ] || mkdir -p /var/run/fetchmail
  43.                 chmod 700 /var/run/fetchmail
  44.                 chown -h -R fetchmail:nogroup /var/run/fetchmail
  45.         else
  46.                 echo "$0: $USER user does not exist!"
  47.                 exit 1
  48.         fi
  49. fi

  50. # add daemon option if user hasn't already specified it
  51. if ! grep -qs '^[[:space:]]*set[[:space:]]\+daemon[[:space:]]' "$CONFFILE"; then
  52.         OPTIONS="$OPTIONS -d 300"
  53. fi

  54. # add syslog option if user hasn't already specified it
  55. if ! grep -qs '^[[:space:]]*set[[:space:]]\+no[[:space:]]\+syslog' "$CONFFILE"; then
  56.         OPTIONS="$OPTIONS --syslog"
  57. fi

  58. # support for ephemeral /var/run
  59. if [ "${PIDFILE%/*}" = "/var/run/fetchmail" ] && [ ! -d ${PIDFILE%/*} ]; then
  60.         mkdir /var/run/fetchmail
  61.         chown -h $USER:nogroup /var/run/fetchmail
  62.         chmod 700 /var/run/fetchmail
  63. fi

  64. # sanity check
  65. if [ ! -d ${PIDFILE%/*} ]; then
  66.         echo "$0: directory ${PIDFILE%/*} does not exist!"
  67.         exit 1
  68. fi

  69. # If the user is going to use a UIDL cache, try to find a better place for the
  70. # UIDL cache than root's homedir. Also create $UIDL if it doesn't exist,
  71. # because the daemon won't have the permission.
  72. if ! grep -qs idfile "$CONFFILE" && [ -d /var/mail ]; then
  73.         OPTIONS="$OPTIONS -i $UIDL"
  74.         touch $UIDL
  75.         chown -h $USER $UIDL
  76.         chmod 0600 $UIDL
  77. fi

  78. # Makes sure certain files/directories have the proper owner
  79. if [ "`stat -c '%U %a' $CONFFILE 2>/dev/null`" != "$USER 600" ]; then
  80.         chown -h $USER $CONFFILE
  81.         chmod -f 0600 $CONFFILE
  82. fi

  83. case "$1" in
  84.         start)
  85.                 if test -e $PIDFILE ; then
  86.                         pid=`cat $PIDFILE | sed -e 's/\s.*//'`
  87.                         if kill -0 $pid ; then
  88.                                 echo "Fetchmail already running with pid $pid (or stale pidfile)."
  89.                                 exit 0
  90.                         fi
  91.                 fi
  92.                 echo -n "Starting mail retrieval agent: fetchmail"
  93.                 if start-stop-daemon -S -o -q -p $PIDFILE -x $DAEMON -u $USER -a /bin/su -- -c "$DAEMON $OPTIONS" $USER; then
  94.                         echo "."
  95.                 else
  96.                         echo " (failed)."
  97.                         exit 1
  98.                 fi
  99.                 ;;
  100.         stop)
  101.                 if ! test -e $PIDFILE ; then
  102.                         echo "Pidfile not found! Is fetchmail running?"
  103.                         exit 0
  104.                 fi
  105.                 echo -n "Stopping mail retrieval agent: fetchmail"
  106.                 if start-stop-daemon -K -o -q -p $PIDFILE -x $DAEMON -u $USER; then
  107.                         echo "."
  108.                 else
  109.                         echo " (failed)."
  110.                         exit 1
  111.                 fi
  112.                 ;;
  113.         force-reload|restart)
  114.                 echo -n "Restarting mail retrieval agent: fetchmail"
  115.                 if ! start-stop-daemon -K -o -q -p $PIDFILE -x $DAEMON -u $USER; then
  116.                         echo " (failed on stop)."
  117.                         exit 1
  118.                 fi
  119.                 sleep 1
  120.                 if start-stop-daemon -S -q -p $PIDFILE -x $DAEMON -u $USER -a /bin/su -- -c "$DAEMON $OPTIONS" $USER; then
  121.                         echo "."
  122.                 else
  123.                         echo " (failed on start)."
  124.                         exit 1
  125.                 fi
  126.                 ;;
  127.         try-restart)
  128.                 if start-stop-daemon -S -t -q -p $PIDFILE -x $DAEMON -u $USER >/dev/null; then
  129.                         exit 0
  130.                 fi
  131.                 $0 restart
  132.                 ;;
  133.         awaken)
  134.                 echo -n "Awakening mail retrieval agent: fetchmail"
  135.                 if [ -r $PIDFILE ]; then
  136.                         su -c $DAEMON $USER <&- >/dev/null 2>&1
  137.                         echo "."
  138.                         exit 0
  139.                 else
  140.                         echo " (not running)."
  141.                         exit 1
  142.                 fi
  143.                 ;;
  144.         debug-run)
  145.                 echo "$0: Initiating debug run of system-wide fetchmail service..." 1>&2
  146.                 echo "$0: script will be run in debug mode, all output to forced to" 1>&2
  147.                 echo "$0: stdout. This is not enough to debug failures that only" 1>&2
  148.                 echo "$0: happen in daemon mode." 1>&2
  149.                 echo "$0: You might want to direct output to a file, and tail -f it." 1>&2
  150.                 if [ "$2" = "strace" ]; then
  151.                         echo "$0: (running debug mode under strace. See strace(1) for options)" 1>&2
  152.                         echo "$0: WARNING: strace output may contain security-sensitive info, such as" 1>&2
  153.                         echo "$0: passwords; please clobber them before sending the strace file to a" 1>&2
  154.                         echo "$0: public bug tracking system, such as Debian's." 1>&2
  155.                 fi
  156.                 echo "$0: Stopping the service..." 1>&2
  157.                 "$0" stop
  158.                 echo "$0: exit status of service stop was: $?"
  159.                 echo "$0: RUNUSER is $USER"
  160.                 echo "$0: OPTIONS would be $OPTIONS"
  161.                 echo "$0: Starting service in nodetach mode, hit ^C (SIGINT/intr) to finish run..." 1>&2
  162.                 if [ "$2" = "strace" ] ; then
  163.                         shift
  164.                         shift
  165.                         [ $# -ne 0 ] && echo "$0: (strace options are: -tt $@)" 1>&2
  166.                         su -c "/usr/bin/strace -tt $@ $DAEMON $OPTIONS --nosyslog --nodetach -v -v" $USER <&- 2>&1 && true
  167.                 else
  168.                         su -c "$DAEMON $OPTIONS --nosyslog --nodetach -v -v" $USER <&- 2>&1 && true
  169.                 fi
  170.                 echo "$0: End of service run. Exit status was: $?"
  171.                 exit 0
  172.                 ;;
  173.         *)
  174.                 echo "Usage: /etc/init.d/fetchmail {start|stop|restart|force-reload|awaken|debug-run}"
  175.                 echo "  start - starts system-wide fetchmail service"
  176.                 echo "  stop  - stops system-wide fetchmail service"
  177.                 echo "  restart, force-reload - starts a new system-wide fetchmail service"
  178.                 echo "  awaken - tell system-wide fetchmail to start a poll cycle immediately"
  179.                 echo "  debug-run [strace [strace options...]] - start a debug run of the"
  180.                 echo "    system-wide fetchmail service, optionally running it under strace"
  181.                 exit 1
  182.                 ;;
  183. esac

  184. exit 0

  185. # vim:ts=4:sw=4:

复制代码
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表