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.).