shell脚本实现每秒执行一次任务

栏目: 服务器 · Linux · 发布时间: 9年前

内容简介:有时候我们需要每秒执行一次命令,通过linux自带的cron却不能实现,新版的cron据说可以精确到秒。很简单的,通过下面的方法,你也能每秒执行一次自己想要的任务了

有时候我们需要每秒执行一次命令,通过linux自带的cron却不能实现,新版的cron据说可以精确到秒。

很简单的,通过下面的方法,你也能每秒执行一次自己想要的任务了:)

1.编写shell脚本

mkdir /root/bin


vi /root/bin/gaojinbo.sh
#!/bin/sh

while [ true ]; do
/bin/sleep 1
/bin/date >>/tmp/date.txt
done 

2.后台运行

nohup /root/bin/gaojinbo.sh &

3.确认每秒执行

tail -f /tmp/date.txt 

完成!

k@ygsi:/cus$ while true ; do sleep 1 ; du mozilla-central/ --max-depth=1; du -h mozilla-central/ --max-depth=1;echo $'\t'; done
k@ygsi:/cus$ while true ; do sleep 1 ; du mozilla-central/ --max-depth=1; du -h mozilla-central/ --max-depth=1;echo $'\t\n'; done

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Learning Python, 5th Edition

Learning Python, 5th Edition

Mark Lutz / O'Reilly Media / 2013-7-6 / USD 64.99

If you want to write efficient, high-quality code that's easily integrated with other languages and tools, this hands-on book will help you be productive with Python quickly. Learning Python, Fifth Ed......一起来看看 《Learning Python, 5th Edition》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

MD5 加密
MD5 加密

MD5 加密工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具