linux 定时执行

人气:263 ℃/2022-11-23 07:59:06

linux 定时执行需要分三步进行,下面是具体介绍:

1、在linux系统下,输入命令:cat /etc/crontab,查看crontab ;

crontab -u //设定特定用户的定时服务

crontab -l //列出当前用户定时服务内容

crontab -r //删除当前用户的定时服务

crontab -e //编辑当前用户的定时服务

2、输入脚本命令: hadoop jar /tycrtest/test2.jar,显示有一个已经设定好的定时任务,比如:每天九点10分执行 ;

3、编辑定时任务:crontab -e 进入编辑界面会显示已存在的定时任务 。

以上就是小编今天的分享了,希望可以帮助到大家。

linux定时执行脚本

Linux使用crontab定时执行shell脚本

一、首先我们先看一下是否安装了crontab。一般情况下Linux系统会自带crontab及crond。如果没有安装,请使用以下指令安装:

yum install vixie-cron yum install crontabs二、 然后我们写一个名字叫做test.sh的shell脚本。很简单,就是输出一段字符。

[root@centos8 crontab]# vim test.sh[root@centos8 crontab]# cat test.sh#!/bin/bashecho "hello world!"# 我们的目的是每分钟执行一次这个shell脚本,所以要再建立一个存放日志的log文件,然后给予test.sh权限。[root@centos8 crontab]# touch log[root@centos8 crontab]# lslog test.sh[root@centos8 crontab]# chmod x test.sh三、然后我们就要使用crontab了,首先进入它的配置文件,在/etc/crontab 中添加我们的调度命令。

[root@centos8 crontab]# vim /etc/crontab[root@centos8 crontab]# cat /etc/crontabSHELL=/bin/bashPATH=/sbin:/bin:/usr/sbin:/usr/binMAILTO=root# For details see man 4 crontabs# Example of job definition:# .---------------- minute (0 - 59)# | .------------- hour (0 - 23)# | | .---------- day of month (1 - 31)# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat# | | | | |# * * * * * user-name command to be executed* * * * * root /opt/crontab/test.sh >> /opt/crontab/log# root表示以root用户身份来运行 >>表示运行脚本后重定向到log文件中CentOS7上的cron命令

systemctl start crond.service //启动服务systemctl stop crond.service //关闭服务systemctl restart crond.service //重启服务systemctl reload crond.service //重新载入配置systemctl status crond.service //查看状态# 或者crond startcrond stopcrond restartcrond reloadcrond status# 查看crontab的日志日志文件为/var/log/croncat /var/log/cronjava启动的脚本crontab定时任务启动失败原因

# crontab定时任务启动脚本失败原因:1.首先手动执行脚本,查看是否能启动2.如果启动失败,脚本写错,如果启动成功,那有概率是java环境变量问题在脚本第一行添加source /etc/profile每次执行重新加载java环境变量文件路径填完整!

推荐

首页/电脑版/网名
© 2025 NiBaKu.Com All Rights Reserved.