在Bash中每秒运行命令? [英] Run command every second in Bash?
问题描述
我想编写一些图像下载器,并在bash上分配它.我所拥有的和我所需要的:
I want to write some image downloader and assign it on bash. What I have and what I need:
我有:
- 命令,效果很好(类似于
wget http://mywebcam.com/image.jpg -O /var/cam/Image.jpg
) -
根权限
- Command, which works fine (something like
wget http://mywebcam.com/image.jpg -O /var/cam/Image.jpg
) Root rights
服务器和网络摄像头之间的快速Internet线路
Fast Internet line between my server and my webcam
我需要什么:
每秒从相机下载图像*(睡眠1?)*并在本地对其进行重写(我的命令执行得很好)
Download image from camera every second*(sleep 1?)* and rewrite it localy (my command do it well) Run this script at once and don't worry about restart (I think I need to create file with bash commands and run it once + set crontab work "on reboot" to this file, right?)
也许有人知道我该怎么办?
Maybe there's someone who knows what should I to do?
推荐答案
如果要每隔一秒运行一次命令(一个命令的结束与下一个命令的开始之间相隔一秒,这与命令不同)每秒运行一次),只需执行以下操作即可:
If you want to run a command at one second intervals (one second between the end of one command and the beginning of the next, which is not the same as running every second), just do:
while sleep 1; do cmd; done
如果您希望重启后开始,方法将取决于您的系统.
If you want that to start on reboot, the method will depend on your system.
这篇关于在Bash中每秒运行命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!