首先新建一个 shell 脚本,输出一段文字到 a.txt 文件中。
vim test.sh
脚本内容为:
#!/bin/bash
echo "hello world" >> ~/a.txt
文件添加可执行权限。
chmod +x test.sh
我们执行一下这个文件
./test.sh
发现生成了a.txt 文件,并且使用 cat a.txt 后发现文件内容为 hello world。
接下来使用 crontab -e 命令打开文件,添加一条语句
* * * * * ~/test.sh
保存退出。(会出现以下提示,说明成功)
我们使用 tail -f a.txt 命令监控a.txt 文件:会发现每隔一分钟,就会多一行 hello world。
说明测试成功。