Dears,
我想在linux crowntab中做一个调度工作,将文件从FTP目录移动(剪切(到本地目录。这不是一次,应该每秒钟都这样做。提前非常感谢大家。
您可以执行循环,但使用crontab无法执行,因为您只能每分钟启动一次。你可以尝试的另一个选项是做60个crontab并做这个
* * * * * sh path/to/your/script
* * * * * sleep 1 && sh path/to/your/script
* * * * * sleep 2 && sh path/to/your/script
* * * * * sleep 2 && sh path/to/your/script
.
.
.
* * * * * sleep 59 && sh path/to/your/script
你可以做的另一件事是
while true;
do sh path/to/your/script &
sleep 1
done
这种方法需要在每次重新启动时启动轮询器。
编辑
让我们假设您的脚本名为ftp_poller.sh,并且您将其放在主脚本文件夹中,让我们将其称为(/home/fitipaldi/scripts/ftp_poller.sh(
ftp_poller.sh内容
#/bin/bash
file=filename
server="example.com"
folder="where_is_the_file" #If it's in the root folder type /
user="username"
pass="supersecretpassword"
/usr/bin/ftp -n << EOF
open ${server}
user ${user} ${pass}
binary
cd ${folder}
get ${file}
del ${file}
EOF
你可以这样做:
* * * * * sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 1 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 2 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 3 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 4 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 5 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 6 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 7 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 8 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 9 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 10 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 11 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 12 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 13 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 14 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 15 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 16 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 17 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 18 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 19 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 20 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 21 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 22 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 23 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 24 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 25 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 26 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 27 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 28 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 29 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 30 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 31 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 32 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 33 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 34 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 35 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 36 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 37 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 38 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 39 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 40 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 41 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 42 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 43 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 44 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 45 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 46 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 47 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 48 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 49 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 50 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 51 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 52 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 53 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 54 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 55 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 56 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 57 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 58 && sh /home/fitipaldi/scripts/ftp_poller.sh
* * * * * sleep 59 && sh /home/fitipaldi/scripts/ftp_poller.sh
好的,这是INSANE,我不建议你使用这个解决方案
但你有另一个解决方案,我认为是更好的
while true;
do sh /home/fitipaldi/scripts/ftp_poller.sh
sleep 1
done
此方法将启动ftp_poller.sh脚本,完成后将等待1秒,然后再次启动。
如果你不在乎流程是否需要超过1秒的时间,并且你想让很多流程都这样做,你可以做
while true;
do sh /home/fitipaldi/scripts/ftp_poller.sh &
sleep 1
done
此方法将启动ftp_poller.sh脚本并将其置于后台,然后休眠1秒并无限次启动。