[关闭]
@JunQiu 2018-11-14T14:03:02.000000Z 字数 3013 阅读 1176

stdin、stdout、stderr cron

linux summary_2018/11


1、stdin、stdout、stderr

1.1、waht is stdin、stdout、stderr?

  1. Type Symbol
  2. standard input 0<
  3. standard output 1>
  4. standard error 2>

1.2、how to use it?

  1. // 告诉 cat input 不是从键盘,而是从文件中来
  2. 20:58:35 cat < text
  3. test
  4. test
  1. // 控制台进程,输出到控制台
  2. 21:03:15 cat text
  3. test
  4. test
  5. // 将text的内容输出到text_1
  6. 21:03:20 cat text > text_1
  7. 21:03:39 cat text_1
  8. test
  9. test
  10. // 将数据输出到txt
  11. 20:44:32 ls -al >> txt (>>追加,>覆盖)
  12. 20:45:06 cat txt
  1. Tips:remember standard error by default is going to the console; the same place as stdout(默认stderrstdout均输出到控制台)
  2. // 将find中的错误比如没有权限放入/dev/null
  3. find / -name "11111111" -print 2> /dev/null
  4. # /dev/null is similar to the "Recycle Bin" under Windows except it's a waste paper basket with a point of no return
  5. // 联合使用,将错误信息发送到/dev/null,输出信息到MyValidOutput
  6. find / -name "*" -print 2> /dev/null > MyValidOutput

1.3、how to undertand it?

1.4、reference


2、cron

2.1、how to use it?

  1. ┌───────────── minute (0 - 59)
  2. ┌───────────── hour (0 - 23)
  3. ┌───────────── day of the month (1 - 31)
  4. ┌───────────── month (1 - 12)
  5. ┌───────────── day of the week (0 - 6) (Sunday to Saturday;
  6. 7 is also Sunday on some systems)
  7. * * * * * command to execute
  8. 特殊符号:
  9. 星号(*):代表所有可能的值,例如month字段如果是星号,则表示在满足其它字段的制约条件后每月都执行该命令操作。
  10. 逗号(,):可以用逗号隔开的值指定一个列表范围,例如,“1,2,5,7,8,9
  11. 中杠(-):可以用整数之间的中杠表示一个整数范围,例如“2-6”表示“2,3,4,5,6
  12. 正斜线(/):可以用正斜线指定时间的间隔频率,例如“0-23/2”表示每两小时执行一次。同时正斜线可以和星号一起使用
  1. Entry Description Equivalent to
  2. @yearly (or @annually) Run once a year at midnight of 1 January 0 0 1 1 *
  3. @monthly Run once a month at midnight of the first day of the month 0 0 1 * *
  4. @weekly Run once a week at midnight on Sunday morning 0 0 * * 0
  5. @daily Run once a day at midnight 0 0 * * *
  6. @hourly Run once an hour at the beginning of the hour 0 * * * *
  7. @reboot Run at startup N/A
  1. // crond服务
  2. service crond start //启动服务
  3. service crond status //服务状态
  4. service crond stop //关闭服务
  5. service crond restart //重启服务
  6. service crond reload //重新载入配置
  7. // crontab命令
  8. crontab(选项)(参数)
  9. -e:编辑该用户的计时器设置;
  10. -l:列出该用户的计时器设置;
  11. -r:删除该用户的计时器设置;
  12. // crontab文件(/etc/crontab)
  13. SHELL=/bin/bash(指定shell
  14. PATH=/sbin:/bin:/usr/sbin:/usr/bin(系统执行命令的路径)
  15. MAILTO=root
  16. 51 * * * * root run-parts /etc/cron.hourly
  17. 24 7 * * * root run-parts /etc/cron.daily
  18. 22 4 * * 0 root run-parts /etc/cron.weekly
  19. 42 4 1 * * root run-parts /etc/cron.monthly
  20. Tips:
  21. 若任务是每小时、每日、每周、或每月地执行,可以将脚本任务添加到/etc/cron.hourly、/etc/cron.daily等目录中。
  22. 当然也可以在/etc/cron.d写定时文件,该目录中的所有文件使用和/etc/crontab一样使用标准语法。

2.2、reference

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注