cygwin安装cron服务

cygwin安装cron服务

cygwin 默认情况下未安装cron服务,

1、下载cron包

打开 cgwin的setup.exe,在select packages 中输入 cron 搜索

package选择:cron:Vixie’s cron

2、设置当前用户密码

默认情况下,登录cygwin的用户没有密码,会导致安装cron服务失败,错误提示:

Do you want to start the cron daemon as a service now? (yes/no) yes
cygrunsrv: Error starting a service: StartService:  Win32 error 1069:

所以,需要设置当前用户密码:

$ passwd
New password:
Re-enter new password:
Password changed.

2、安装cron服务

$ cron-config
The cron daemon can run as a service or as a job. The latter is not recommended.
Cron is already installed as a service under account .\hury.
Do you want to remove or reinstall it? (yes/no) yes
OK. The cron service was removed.

Do you want to install the cron daemon as a service? (yes/no) yes
Enter the value of CYGWIN for the daemon: [ ] cron

You must decide under what account the cron daemon will run.
If you are the only user on this machine, the daemon can run as yourself.
   This gives access to all network drives but only allows you as user.
To run multiple users, cron must change user context without knowing
  the passwords. There are three methods to do that, as explained in
  http://cygwin.com/cygwin-ug-net/ntsec.html#ntsec-nopasswd1
If all the cron users have executed "passwd -R" (see man passwd),
  which provides access to network drives, or if you are using the
  cyglsa package, then cron should run under the local system account.
Otherwise you need to have or to create a privileged account.
  This script will help you do so.
Do you want the cron daemon to run as yourself? (yes/no) yes

Please enter the password for user 'hury':
Reenter:
Running cron_diagnose ...
WARNING: You do not currently have a crontab file.

... no problem found.

Do you want to start the cron daemon as a service now? (yes/no) yes
OK. The cron daemon is now running.

$ ps -l
      PID    PPID    PGID     WINPID   TTY         UID    STIME COMMAND
     3180   16876    3180      11600  ?         197609 08:31:02 /usr/sbin/cron

cron命令

crontab -e #编辑任务
crontab -l #查看任务列表
crontab -r #删除任务
cronevents #查看执行情况

新增cron任务

# 新增测试脚本
$ echo "echo "@`date +'%Y-%m-%d %H:%M:%S'`" hello, crontab is running">crontabTest.sh
$ crontab -e
* * * * * /home/hury/crontabTest.sh>/home/hury/crontabTest.log

查看cron任务

$ crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.RGxr32kWAC installed on Fri May 18 08:55:02 2018)
# (Cron version V5.0 -- $Id: crontab.c,v 1.12 2004/01/23 18:56:42 vixie Exp $)
* * * * * /home/hury/crontabTest.sh>/home/hury/crontabTest.log

你可能感兴趣的:(linux)