在过去的 2 周里,每天大约 3 到 7 个小时,我一直在尝试让这个脚本将正确的日期写入"settings.xml"文件。我每天都在互联网上搜索,试图找到例子,但没有运气。
我正在尝试制作一个演示站点,并找到了这个脚本,我正在尝试了解它是如何工作的。我仔细检查了每个步骤,看看每个步骤是否有效。到目前为止,97% 的完整脚本都可以工作,但我不明白为什么脚本的这一部分没有在每次脚本启动时添加"30 分钟"。
所以我的问题是:
如何让下面这部分脚本写入"settings.xml"文件,并在脚本启动时间中添加"30 分钟"或"2 小时"?
谢谢,马克·
====== 这个脚本在这里 === 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
}
sed 上的 -i 选项对占位符文件进行就地编辑。相反,您可以做一个sed'...代码...">设置.xml并保持占位符文件不变。那么你的脚本将是可重复的。