Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Shells Virtual Desktop
BMail.ag - Secure Email Service
Server.net
CPLicense.net
VPS Server
Buy VPN
Vultr
VMs for AI
HostDare
HostDare
ReliableSite White-Label Dedicated Hosting for Resellers
25% Recurring Discount on NVMe VPS
InterServer VPS
BMail.ag - Secure Email Service
Best VPN
High-Performance Bare Metal Server Solutions
Karvl.com
Server Mania Cloud Hosting
DataWagon Hosting
AlphaVPS Hosting
Evoxt.com
Clouvider
VPS Hosting with NVMe
Residential IPs in the US & 4G Mobile Proxies in EU & US with Unlimited Bandwidth
ReliableSite White-Label Dedicated Hosting for Resellers
Rabisu - Hosting Solutions
CloudLinux
Shells Virtual Desktop
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Is It Normal That Cron Won't Run For A Cloned VPS (Hetzner) ?

nvidiannvidian Member
edited June 2024 in Help

Hello,

For some reason, I have to quick build a vps by cloning a previously works one at Hetzner Cloud. Its just a LEMP server with a few websites in it. The cron job was work with no issue at the previous vps - one of the main cron job is backup web files & database to my backup server on different provider.

After the new vps running (LEMP stack works), I deleted the previous (old) server. But after many days I noticed that the backup cron job was not run, I checked the very first step log and it shows nothing. It only run if I executed it manually.

Then I created a very simple bash script (insert / append current date to file) for testing purpose. And I found that simple script was also not run at all. I was also check if my root password has expired (if it has to do with this issue), use vi instead of nano, use crontab import from file etc but still, my cronjob wont run.

I then used systemd timer to replace crond only to discover that the simple scipt and even my backups were now running.

I don't have much knowledge of how Linux OS works especially in VM environment, is it normal that a cloned vps would have issue in cron/crontab ? How to fix cron/crontab job on a cloned vps ?

Thank you

Comments

  • CrabCrab Member
    edited June 2024

    There's no difference between VM and non-virtualized environment when it comes to cron scripts. Do you have execute bit properly set for the script? Are you running it with a proper user? Are the commands you run in PATH? Does cron log show that it is running? Is your crontab format proper? There are a lot of things that go wrong.

  • CrabCrab Member
    edited June 2024

    Accidental double post.

  • nvidiannvidian Member
    edited June 2024

    @Crab said:
    There's no difference between VM and non-virtualized environment when it comes to cron scripts. Do you have execute bit properly set for the script? Are you running it with a proper user? Are the commands you run in PATH?

    This is the cronjob for the simple script (both not work)
    `* * * * * /usr/bin/sh /root/mycron/test.sh > /root/mycron/test.log
    OR

            • root /usr/bin/sh /root/mycron/test.sh > /root/mycron/test.log`
  • nvidiannvidian Member
    edited June 2024

    @nvidian said:

    @Crab said:
    There's no difference between VM and non-virtualized environment when it comes to cron scripts. Do you have execute bit properly set for the script? Are you running it with a proper user? Are the commands you run in PATH?

    This is the cronjob for the simple script (both not work)
    `* * * * * /usr/bin/sh /root/mycron/test.sh > /root/mycron/testlog.txt
    OR

            • root /usr/bin/sh /root/mycron/test.sh > /root/mycron/testlog.txt`

    This is the content of test.sh
    `#!/bin/sh

    echo -e date > test.log`

  • CrabCrab Member
    edited June 2024

    Put #!/usr/bin/sh to the first line of /root/mycron/test.sh and leave it out of crontab. The first example is not proper since you don't have the user specified. Does cron log at /var/log show that it is getting executed?

  • Yeah, i don't really know what's OP's definition of cloning but in general everything should just run after maybe adjusting network settings. I have a VPS that has been cloned (by mirroring the disk) across at least 5 VMs at 2 providers and it runs like on its first day.

  • @totally_not_banned said:
    Yeah, i don't really know what's OP's definition of cloning but in general everything should just run after maybe adjusting network settings. I have a VPS that has been cloned (by mirroring the disk) across at least 5 VMs at 2 providers and it runs like on its first day.

    Create VPS from a snapshot

  • nvidiannvidian Member
    edited June 2024

    @Crab said:
    Put #!/usr/bin/sh to the first line of /root/mycron/test.sh and leave it out of crontab. The first example is not proper since you don't have the user specified. Does cron log at /var/log show that it is getting executed?

    Nothing as it hasnt even run.

    Sorry for the typo, of course I put #!/usr/bin/sh at the first line. And dont forget that the script was running well on previous VPS.

  • CrabCrab Member

    Do you have execute bit on it? What does ls -al /root/mycron/test.sh show?

  • LeviLevi Member

    chmod u+x script.sh

  • tenjitenji Member
    edited June 2024

    There are journal log you can check
    journalctl --no-pager --since <date-start> --until <date-end> -u cron | less
    note :
    --no-pager : I hate the internal pager, prefer to pipe it to less
    <date> : replace with 'yyyy-mm-dd 00:00:00', you can omit the time
    -u : unit name, in your case, it's cron related thing

    Don't really know if there are errors will shown here extensively :|

  • @Crab said:
    Do you have execute bit on it?

    Yes, I have executed it manually.

    @Crab said:
    What does ls -al /root/mycron/test.sh show?

    Of course the path is right.

    @Levi said:
    chmod u+x script.sh

    Yes, I already make it executable.

  • nvidiannvidian Member
    edited June 2024

    I think maybe I'm just unlucky, the snapshot (instant image) was taken while the VM was running. Maybe somehow it got corrupted.

    At least now my backups can be scheduled using systemd timer.

  • lc475lc475 Member

    Have you checked crond process is running?

    If you clone a system, sometimes service cannot start properly because the .pid file exists. Delete the pid file, then start the service should work.

  • check your timezone. For some reason the timezone the cronjob on my KSLE using gmt+8 instead of utc.

  • nvidiannvidian Member
    edited June 2024

    @lc475 said:
    Have you checked crond process is running?

    If you clone a system, sometimes service cannot start properly because the .pid file exists. Delete the pid file, then start the service should work.

    Thank you, it could be the culprit. But I have uninstalled & reinstalled cron, is that count ?

    @yokowasis said:
    check your timezone. For some reason the timezone the cronjob on my KSLE using gmt+8 instead of utc.

    Yes, I have set "CRON_TZ" in the very first line of my crontab. Besides, in the testing script I have set it to every minute in crontab, so I think timezone is not an issue here.

Sign In or Register to comment.