SSH:如何添加" 2小时"到" targetHour =`date --date" now + $ {nextrun}" +%k`"并写入" settings.xml"每次脚本启动?

时间:2016-03-22 00:05:18

标签: date ssh crontab

过去2周,每天大约3到7小时,我一直试图让这个脚本把正确的日期写入" settings.xml"文件。我每天搜索互联网,试图找到例子,但没有运气。

我正在尝试制作一个演示网站并找到这个脚本,我试图了解它是如何工作的。我走了每一步,看看每个步骤是否有效。到目前为止,97%的完整脚本有效,但我不明白为什么脚本的这一部分没有添加" 30分钟"每次此脚本启动时。

所以我的问题是:
如何使下面脚本的这一部分写入" settings.xml"文件并添加" 30分钟"或者" 2小时"到脚本开始的时候?

谢谢Mark E.

======这个脚本在这里=== SSH ==============================

# How often the demo site will be refreshed?  
# You must keep in sync the crontab refresh time and this one, eg 30 minutes refresh in crontab, 30 minutes here  
# this value will be used to calculate and update the module that display a countdown  
# nextrun=1 months 2 days 3 hours 4 minute 3 sec   

nextrun="30 Minute"  

packagedestination="/home/username/public_html/demosite/"  

# This create a new file that can be checked for creation time in a dedicated Joomla! module  
function updateJoomlaModule() {  
base="${packagedestination}flashxml/countdownfx"  
file="${base}/settings.placeholder.xml";  
targetfile="${base}/settings.xml";  
if [ -f "$file" ]  
then  
nextRun=`date --date "now +${nextrun}"`  
targetYear=`date --date "now +${nextrun}" +%Y`  
targetMonth=`date --date "now +${nextrun}" +%m`  
targetDay=`date --date "now +${nextrun}" +%e`  
targetHour=`date --date "now +${nextrun}" +%k`  
targetMinute=`date --date "now +${nextrun}" +%M`  
echo "Next update $nextRun Updating file at $file"  
sed -i "s/_targetYear/${targetYear}/g;s/_targetMonth/${targetMonth}/g;s/_targetDay/${targetDay}/g;s/_targetHour/${targetHour}/g;s/_targetMinute/${targetMinute}/g" $file  
echo "Move ${file} to ${targetfile}"  
cp ${file} ${targetfile}  

echo "<html><body></body></html>" > ${base}/index.html  
else  
echo "countdownfx module not detected!";  
fi  
}  

1 个答案:

答案 0 :(得分:0)

sed上的-i选项会对占位符文件进行就地编辑。相反,你可以做一个sed&#39; ...代码...&#39; &GT; setting.xml并保留占位符文件。然后你的脚本将是可重复的。