diff --git a/google_image_sitemap.module b/google_image_sitemap.module
index 6e00152..50f00e4 100644
--- a/google_image_sitemap.module
+++ b/google_image_sitemap.module
@@ -315,7 +315,9 @@ function _google_image_sitemap_build($sitemap_id) {
       drupal_set_message(t("No Images found!"));
     }
   }
-  drupal_goto(isset($_GET['destination']) ? $_GET['destination'] : GOOGLE_IMAGE_SITEMAP_ADMIN_PATH);
+  if (!drupal_is_cli()) {
+    drupal_goto(isset($_GET['destination']) ? $_GET['destination'] : GOOGLE_IMAGE_SITEMAP_ADMIN_PATH);
+  }
 }
 
 /**
@@ -351,3 +353,20 @@ function google_image_sitemap_node_type_delete($info) {
   db_delete('google_image_sitemap')
     ->condition('node_type', $info->type);
 }
+
+/**
+ * Implements hook_cron()
+ */
+function google_image_sitemap_cron() {
+
+  // Get image sitemap information from db
+  $query = db_select('google_image_sitemap', 'g');
+  $query->fields('g');
+  $result = $query->execute();
+
+  while ($gis_obj = $result->fetchObject()) {
+    // Eebuild the sitemap
+    _google_image_sitemap_build($gis_obj->sid);
+  }
+
+}
