Linux下使用crontab执行一个shell脚本

Posted 技术改变命运Andy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux下使用crontab执行一个shell脚本相关的知识,希望对你有一定的参考价值。

####################

root路径下新建一个hello.sh文件,内容如下:

#!/bin/bash
echo 123

注意:

1,一定要以.sh结尾
2,#!/bin/bash 是必须要写的
3,通过chmod命令赋予该脚本的执行权限chmod 755 hello.sh,否则没有执行权限

 

######################

手动执行这个shell文件

sh  /root/hello.sh

 

########################

定时执行这个文件

* * * * * sh /root/hwy/hello.sh >> /root/hwy/hello.log

注意:

1,>> 符号 指定文件获取内容的存放位置

 

 

#########################

以上是关于Linux下使用crontab执行一个shell脚本的主要内容,如果未能解决你的问题,请参考以下文章

使用crontab,让linux定时执行shell脚本

使用crontab,让linux定时执行shell脚本

Crontab 让linux定时执行shell脚本

Linux crontab 定时任务命令详解

Linux 定时执行shell脚本命令之crontab

在linux下怎么让一个脚本定时运行