Google Sitemap cron

I am using the Google Sitemap add-on and I wanted to use a cron job to update the sitemap every day. There is a given command to do this, which is:

php /path/to/cart/admin.php --dispatch=xmlsitemap.generate

needless to say this does not work because admin.php is a password-protected back-end file so it cannot be called up without adding the password to the command. However even when you do add the password, the command still throws up an error.

I also tried simply calling up the link on the “Regenerate a sitemap” button ( using a curl command, but strangely that link will not generate a sitemap even if you are logged it. It only works when you actually click the button itself, not when you copy and paste the link.

If someone can help with a working cron command, I would be much obliged.

You need to replace the path/to… e.g.

/usr/local/bin/php /home/YOUR_DOMAIN/public_html/YOUR_ADMIN.PHP --dispatch=xmlsitemap.generate

And then you will find it in var/files/google_sitemaps/COMPANY_NUMBER

The path will be specific to your instalation, replace the items I have capitilised and it may work, but even the starting path may have been changed from cpanel defaults and your hosting provider can provide assitane with path.

1 Like

Thanks for that, I saw where the error was on my path and corrected it. The cron job now runs on terminal. However when I open the sitemap using https://MYDOMAIN/index.php?dispatch=xmlsitemap.view or https://MYDOMAIN/sitemap.xml it seems there is still the old data as shown by <lastmod.>2024-06-18<./lastmod>. which I assumed would be <.lastmod>2024-06-19<./lastmod>. What URL should I then put in the Google Search console so it gets the latest sitemap?

Possibly a difference in your server time vs local time.

I managed to see that xml file. The file updates only when I use the “Regenerate a sitemap” button on the add-on, it doesn’t update when I run the cron job via Terminal. This is the output I am getting from Terminal:

[MYVPSNAME ~]$ /bin/ea-php81 /home/MYACCOUNT/MYDOMAIN/admin.php --dispatch=xmlsitemap.generate
Status: 302 Found
X-Frame-Options: SAMEORIGIN
Content-Type: text/html; charset=utf-8
Set-Cookie: sid_admin_eb591=5dacc8615a7440cc21b552f9070c3584-A; expires=Wed, 03-Jul-2024 10:04:59 GMT; Max-Age=1209600; path=/; domain=.MYDOMAIN; HttpOnly; SameSite=lax
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Content-Security-Policy: frame-ancestors ‘self’;
Location: https://MYDOMAIN/admin.php?%2Fhome%2FMYACCOUNT%2FMYDOMAIN%2Fadmin_php=&--dispatch=xmlsitemap.generate

I am not a programmer so no idea whether that means there is a problem with running the job?

Most file structures include public_html.

[MYVPSNAME ~]$ /bin/ea-php81 /home/MYACCOUNT/MYDOMAIN/public_html/admin.php --dispatch=xmlsitemap.generate

This one is a subdomain so it’s not sitting in public_html