- Ruby 2.1.1
- phantomjs
- Clone the script.
- Run
bundle install
. - Set env variables
DOMCHEL_EMAIL
,DOMCHEL_PASSWORD
andDOMCHEL_REPORT_TO_EMAILS
in the~/.profile
file. - Add the
domchel_message_updater.rb
file to cron.
.profile
example:
export DOMCHEL_EMAIL=me@example.com
export DOMCHEL_PASSWORD=my_secret_password
export DOMCHEL_REPORT_TO_EMAILS=me@example.com # Emails to send successful update reports to, comma separated
To add the script to run as a current user run:
crontab -e
And then add the following line to the edit window:
0 * * * * /bin/bash -l -c 'cd /Users/your_user_name/cron_scripts/domchel_ru_autoupdater && ./domchel_message_updater.rb' > /dev/null 2>&1
where /Users/your_user_name/cron_scripts/domchel_ru_autoupdater
is the path to your scriptfile.
This line schdules running the script hourly. On each run, the script would check the last update time. If it's been more than 24 hours since the last update it would try to update the message. Otherwise it would do nothing.
The script is scheduled hourly, not daily, to deal with some unexpected errors on the server side - if it was time to update, but it fails for some reason, it would retry again in an hour.
All the messages from the script is suppressed by the > /dev/null 2>&1
part of the command above.
For details look here
and here.
- 0 - successfully updated
- 1 - unable to authorize
- 2 - there were errors on the site when updating
- 3 - no need for update yet (updated recently)
The script saves finish time and exit code to the .last_run
file on each execution.
The second script of the repo aims to monitor views count of the first message on Domchel. It saves this information to a csv file with some additional information for future analysis.
To schedule the script add this to your crontab (see above):
*/10 * * * * /bin/bash -l -c 'cd /Users/your_user_name/cron_scripts/domchel_ru_autoupdater && ./domchel_views_counter.rb' > /dev/null 2>&1
It would run the script each 10 minutes.
The resulting file is views_info.csv
.