我需要每月運行一次玉米作業來更新軟件許可證。如何使用外部字符串在cron作業中運行命令
許可證已準備好在遠程服務器上的文本文件中(例如:http://codebox.ir/soft/license.txt)並每月更新一次。
license.txt內容示例「tev3vv5-v343」。
我要搶許可證,並把一些命令:
# update xxxx-xxxx
我怎樣才能使這個?
- 的CentOS 6.4
我需要每月運行一次玉米作業來更新軟件許可證。如何使用外部字符串在cron作業中運行命令
許可證已準備好在遠程服務器上的文本文件中(例如:http://codebox.ir/soft/license.txt)並每月更新一次。
license.txt內容示例「tev3vv5-v343」。
我要搶許可證,並把一些命令:
# update xxxx-xxxx
我怎樣才能使這個?
寫一個腳本,從您的REMOTESERVER獲取文件
wget http://codebox.ir/soft/license.txt
然後你拿到鑰匙的是,文本文件和管道它到你的UpdateCommand
update `cat license.txt`
注意反引號,所以你的腳本可能看起來像這樣
#!/bin/sh
#
# This script fetches and updates the licensefile
#
wget http://codebox.ir/soft/license.txt;
update `cat license.txt`;
使文件可執行
chmod +x updateLicense.sh
,並把它放在你的crontab
cd /path/to/script;./updateLicense.sh
或以保持其緊湊,allthough我會檢查,如果該文件是在預期的格式第一。
#!/bin/sh
#
# This script fetches and updates the licensefile
#
update `wget http://codebox.ir/soft/license.txt`;
並與檢查,如果取指成功
#!/bin/sh
#
# This script fetches and updates the licensefile
#
URL = http://codebox.ir/soft/license.txt
wget_output=$(wget -q "$URL")
if [ $? -ne 0 ]; then
update $wget_output
fi
不,你可以進一步發展的話,我會建議檢查關鍵的格式更新
#!/bin/sh
#
# This script fetches and updates the licensefile
#
# Define URL
URL = http://codebox.ir/soft/license.txt
# Fetch content
wget_output=$(wget -q "$URL")
# Check if fetch suceeded $? is the returnvalue of wget in this case
if [ $? -ne 0 ]; then
# Use mad Regexskillz to check format of licensekey and update if matched
if [[ $wget_output == [a-z0-9]+-[a-z0-9]+ ]] ; then update $wget_output; fi
fi
我以前也返回一些值,以進一步提高您的腳本的質量,我也將URL和正則表達式傳遞到函數,以保持腳本可重用,但這是一個品味問題
您可以直接說'update $(wget ...)'。 – fedorqui 2014-10-09 09:26:27
可能重複[使用Linux如何將文件的內容作爲參數傳遞給可執行文件?](http://stackoverflow.com/questions/4241369/using-linux-how-can-i-pass-將文件內容作爲參數傳遞給執行文件) – Jeredepp 2014-10-09 09:25:56