Cronjobbing n the Cloud

I’m super pleased with getting cogdogblog.com hoisted to the cloud, and I admit I have no good clue how everything works.

On my shared host version, I had set up a cron job o regularly delete comments flagged as spam from my database, keeping it clean from cruft. My cronjob command was:

mysql -u blog -p{password} --database={dbname} -Bse "DELETE FROM wp_comments WHERE comment_approved = 'spam'"

Can I do something like this in the clouds?

Yes absolutely!

You can open a terminal in the environment on Reclaim Cloud, then:

crontab -e

To edit the cron just like most linux boxes, or if you want to avoid the terminal or vim, you can do it from the “config” tool on Reclaim Cloud. Click on the wrench, then the cron bookmark in the sidebar, then double click on litespeed to edit that file.

You will need to use cron expressions for the scheduling (check out https://crontab.guru for help!) so stuff like this will work:

Delete the spam daily:

@daily mysql -u blog -p{password} --database={dbname} -Bse "DELETE FROM wp_comments WHERE comment_approved = 'spam'"

Delete the spam at 6am every Monday:

0 6 * * 1 mysql -u blog -p{password} --database={dbname} -Bse "DELETE FROM wp_comments WHERE comment_approved = 'spam'"

I am just getting around to trying this Taylor, cfor the @daily version-- I used the values for {password} and {dbname} from my wp-config and saved.

I will know its working if the comments marked as spam in my wp dashboard are cleaned our, right?

Yep! Sounds like it’s working but there are a few other ways to test:

In general to test out a cron job I’ll try first running it in the terminal (without the timing info) and then I’ll try scheduling the cron to run frequently, like every minute but take its output and write it to a file I can examine.

Here’s an example of setting that command to run every minute but to write all of its output (if it has any standard error or standout out) to a file at /home/litespeed/delete_blog_spam_cron.log

* * * * * mysql -u blog -p{password} --database={dbname} -Bse "DELETE FROM wp_comments WHERE comment_approved = 'spam'" > /home/litespeed/delete_blog_spam_cron.log 2>&1

If something is going wrong I’d expect to see some error(s) in the file. Once it’s working you can add just the schedule back to a more reasonable one instead of every minute.