我在bash脚本中有此安装程序shell脚本。
将新文件复制到目标目录
mv /target/data.ini /target/data_$(date +"%Y%m%d_%H%M%S").ini
rm -f /target/data.ini
cp /install/data.ini /target/data.ini
由于某些原因,cp命令并不总是复制文件。
以前的mv或rm操作是否可能未完成?
自从它作为脚本的一部分运行以来,我看不到任何错误;如果我手动执行命令,则可以正常工作。
如果我手动执行命令,则可以正常工作。
有一个线索。这可能是路径问题。当我写一些东西时,尤其是为脚本写东西时,我总是喜欢包含命令的路径。
$ which date
/usr/bin/date
然后,我将在脚本中添加错误检查:
if [ -f /target/data.ini ]
then
# Note spaces separating the parenthesis from the command
/bin/mv /target/data.ini /target/data_$( /usr/bin/date +"%Y%m%d_%H%M%S" ).ini
if [ $? -ne 0 ]
then
echo "Error on MV command"
exit
fi
else
echo "Error: Can't find /target/data.ini"
exit
fi
cp /install/data.ini /target/data.ini
#Same type of error checking here
这应该可以解决或揭示您的错误。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句