我想写一个shell脚本,检查某个文件,archived_sensor_data。Json,如果存在,删除它。在http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html网站上,我尝试了以下方法:
[-e archived_sensor_data.json] && rm archived_sensor_data.json
但是,这会抛出一个错误
[-e: command not found
当我尝试使用。/test_controller命令运行生成的test_controller脚本时。代码出了什么问题?
如果你正在使用NFS,“test”是一个更好的解决方案,因为你可以为它添加一个超时,以防NFS宕机:
time timeout 3 test -f
/nfs/my_nfs_is_currently_down
real 0m3.004s <<== timeout is taken into account
user 0m0.001s
sys 0m0.004s
echo $?
124 <= 124 means the timeout has been reached
一个"[-e my_file]"构造将被冻结,直到NFS再次起作用:
if [ -e /nfs/my_nfs_is_currently_down ]; then echo "ok" else echo "ko" ; fi
<no answer from the system, my session is "frozen">