Tuesday, 15 February 2011

linux - How to run command in cron job with external string -



linux - How to run command in cron job with external string -

i need run corn job every month update software license.

the license ready in text file on remote server (example: http://codebox.ir/soft/license.txt) , update every month.

license.txt content illustration "tev3vv5-v343".

i want grab license , set in command:

# update xxxx-xxxx

how can create this?

centos 6.4

write script fetches file remoteserver

wget http://codebox.ir/soft/license.txt

then key out of textfile , pipe updatecommand

update `cat license.txt`

note backticks, script this

#!/bin/sh # # script fetches , updates licensefile # wget http://codebox.ir/soft/license.txt; update `cat license.txt`;

make file executable

chmod +x updatelicense.sh

and set in crontab

cd /path/to/script;./updatelicense.sh

or maintain compact, allthough check if file in expected format first.

#!/bin/sh # # script fetches , updates licensefile # update `wget http://codebox.ir/soft/license.txt`;

and checking if fetch succeeded

#!/bin/sh # # script fetches , updates licensefile # url = http://codebox.ir/soft/license.txt wget_output=$(wget -q "$url") if [ $? -ne 0 ]; update $wget_output fi

no can develop further, i'd advise check format of key before updating

#!/bin/sh # # script fetches , updates licensefile # # define url url = http://codebox.ir/soft/license.txt # fetch content wget_output=$(wget -q "$url") # check if fetch suceeded $? returnvalue of wget in case if [ $? -ne 0 ]; # utilize mad regexskillz check format of licensekey , update if matched if [[ $wget_output == [a-z0-9]+-[a-z0-9]+ ]] ; update $wget_output; fi fi

i'd homecoming values farther raise quality of script, i'd pass url , regex function maintain script reusable that's matter of taste

linux terminal cron centos

No comments:

Post a Comment