///Gallery2 Cron-job to automate “build-all-thumbnail/resizes”

Gallery2 Cron-job to automate “build-all-thumbnail/resizes”

Want create site? Find Free WordPress Themes and plugins.

Below is a script for Gallery2 to automate the building and resizing of thumbnails and resizes. Schedule it as a cron-job (cut and paste it to “gallery2-rebuilt” in your “/etc/cron.daily” folder).
You can even schedule this script from a remote linux machine which does not host the Gallery2. Dependencies are minimal (no CURL used)!


#!/bin/sh

########################################################
#SCRIPT TO REBUILT THE (BROKEN)IMAGES AND THUMBNAILS EVERY NIGHT.	
#IT ONLY PROCESSES BROKEN IMAGES OR NOT-YET-PROCESSED IMAGED.
#DATE: 29 JULY 2008 / AUTHOR: ROEL BROERSMA
#URL: WWW.ROELBROERSMA.NL / VERSION 1.0
#CONTACT: ROEL -AT- GIGAWEB -DOT- NL
########################################################

TMP_PATH="/tmp"			#LOCAL TEMP PATH (no last slash)
G2_URL="http://domain/gallery"	#FULL URL TO GALLERY2 (no last slash)
G2_USER="admin"			#GALLERY2 USERNAME WITH ENOUGH RIGHTS
G2_PASS="secret"			#GALLERY2 PASSWORD

#GET THE LOGIN PAGE OF GALLERY2 (LOGIN WITH ADMIN ACCOUNT).
wget --quiet --cookies=on --output-document=$TMP_PATH/g2_loginpage --save-cookies $TMP_PATH/myg2cookies "$G2_URL/main.php?g2_controller=core.UserLogin&g2_form[formName]=UserLogin&g2_form[username]=$G2_USER&g2_form[password]=$G2_PASS&g2_form[action][login]=Login"

#GRAB THE AUTH_TOKEN (WE NEED IT IN THE NEXT STEP).
AUTHTOKEN=`cat $TMP_PATH/g2_loginpage | grep -m1 g2_authToken | cut -d"_" -f9 | cut -d"%" -f2 | cut -d"D" -f2-`

#EXECUTE THE MAINTENANCE ACTION.
wget --quiet --cookies=on --load-cookies $TMP_PATH/myg2cookies "$G2_URL/main.php?g2_controller=core.AdminMaintenance&g2_form%5Baction%5D%5BrunTask%5D=1&g2_taskId=BuildDerivativesTask&g2_authToken=$AUTHTOKEN"

#CLEAN-UP TEMP FILES.
rm -f $TMP_PATH/g2_loginpage
rm -f $TMP_PATH/myg2cookies

Offcourse you can use the above script to script any Gallery2 action (i.e.: Removing the database or template cache, clearing user sessions, etc.).

Did you find apk for android? You can find new Free Android Games and apps.
By |2017-01-11T14:33:18+00:00July 29th, 2008|Technical|3 Comments

3 Comments

  1. Ipstenu 18 February 2009 at 19:59

    Awesome +1!

    I too had to change my AUTHTOKEN from -f9 (in my case it was -f11)

    If you’re having issh with this, run it once with the rm for g2_loginpage commented out, and then run

    cat /tmp/g2_loginpage | grep -m1 g2_authToken | cut -d"_" -f# | cut -d"%" -f2 | cut -d"D" -f2-

    from command line, changing f# up and down until it spits out something like f05v09ff (you’ll know it’s wrong when you see it)

    Huzzah! Cron cleanup is underway!

  2. […] a maintenance task to use the EXIF data to power the maps module of Gallery2, so using Roel Broersma’s excellent script to run the maintenance tasks, these can be scheduled with the extra […]

  3. Kevin Blake 15 November 2008 at 20:26

    Awesome. Exactly what I needed – thanks for sharing :)
    I had to make a minor edit to the second cut command, but could be all down to my templates / particular install.

    AUTHTOKEN=… | cut -d”_” -f8 | …

Leave A Comment

The store is not open yet, we're planning a launch date of 20 March 2017 ! Dismiss