【发布时间】:2012-09-16 01:09:39
【问题描述】:
有两个目录,其中包含一些文件。我正在使用 Hadoop,这两个目录都是 Hadoop 文件系统。
目录的第一个位置-
/sys/edw/
目录的第二个位置-
/apps/only/
我想看看these two directories 是否有一些files or not。如果它们包含一些文件,则continue and execute my other shell scripts,但如果它们不包含任何文件,则wait for half an hour,然后再次检查文件是否已到达这两个目录。
如果已经到达,则执行其他shell脚本,如果没有到达,则再次等待半小时,并继续每半小时检查一次。
算法-
If [ hadoop fs -ls /sys/edw/ AND hadoop fs -ls /apps/only/ ]
then
continue executing my other shell scripts
but if condition is not true
wait for half an hour and then check again with the if loop and keep on looking every half an hour until the if condition is not true
我只想在上面的 if 条件为真时执行下面的脚本。
query.sh
基本上我有几个脚本我只想运行if condition is true 否则继续检查every half an hour 并查看if condition is true or not 是否。
我在奔跑SunOS 5.1
更新代码:-
我正在尝试类似下面的操作,并且此目录中不存在文件(/apps/hdmi/20120916),因此它应该休眠半小时,但它不会休眠,而是执行其他 shell 脚本它不应该这样做-
while [ ! hadoop fs -ls /apps/hdmi/20120916 ]; do
sleep 1800
done
echo "Hello new11"
pwd
我做错了什么?
再次更新:-
while ! hadoop fs -ls /apps/hdmi/20120916 ; do
sleep 1800
done
echo "Hello new11"
pwd
我也尝试过上面的那个,但是这个目录不存在(/apps/hdmi/20120916),而不是睡半个小时,它会打印不应该发生的Hello new11。它应该等待半个小时。我还缺少什么吗?我正在运行SunOS 5.1
【问题讨论】:
-
阅读
man cron。cron可让您执行定期任务,非常适合这项工作。 -
@nneonneo 将其作为答案,以便他接受。
-
实际上,让我直截了当——您希望脚本在条件为真后退出并停止检查?
-
一旦条件成立,我需要执行
query.sh script否则继续每半小时检查一次,直到条件成立。 -
去掉括号:
while ! hadoop fs -ls /apps/hdmi/20120916; do ...