MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    Cronjob

    Scheduled Pinned Locked Moved Solved Troubleshooting
    17 Posts 5 Posters 8.3k Views 4 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • CyruS1337C Offline
      CyruS1337 Project Sponsor
      last edited by

      Good evening

      I’d like to see my MagicMirror restart at a certain time each day. What should I enter in the crontrab? I have already tried x variants, but unfortunately it never worked.

      27 17 * * * Command pm2 restart mm
      

      The sudo reboot command works fine.

      27 17 * * 5 sudo poweroff
      
      1 Reply Last reply Reply Quote 0
      • garblefluxG Offline
        garbleflux Project Sponsor
        last edited by garbleflux

        @CyruS1337 said in Cronjob:

        Good evening

        I’d like to see my MagicMirror restart at a certain time each day. What should I enter in the crontrab? I have already tried x variants, but unfortunately it never worked.

        27 17 * * * Command pm2 restart mm
        

        The sudo reboot command works fine.

        27 17 * * 5 sudo poweroff
        

        Did you forget to write the full command? Try pm2 restart mm.sh
        By the way: I prefere the online crontab generator (https://crontab-generator.org/). It’s very easy.
        Regards Mike

        1 Reply Last reply Reply Quote 0
        • CyruS1337C Offline
          CyruS1337 Project Sponsor
          last edited by

          Thanks for the link, but it still does not work :(

          # Edit this file to introduce tasks to be run by cron.
          #
          # Each task to run has to be defined through a single line
          # indicating with different fields when the task will be run
          # and what command to run for the task
          #
          # To define the time you can provide concrete values for
          # minute (m), hour (h), day of month (dom), month (mon),
          # and day of week (dow) or use '*' in these fields (for 'any').#
          # Notice that tasks will be started based on the cron's system
          # daemon's notion of time and timezones.
          #
          # Output of the crontab jobs (including errors) is sent through
          # email to the user the crontab file belongs to (unless redirected).
          #
          # For example, you can run a backup of all your user accounts
          # at 5 a.m every week with:
          # 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
          #
          # For more information see the manual pages of crontab(5) and cron(8)
          #
          # m h  dom mon dow   command
          #
          #MONTAG BIS SONNTAG UM 19:55 MAGICMIRROR RESTART
          55 19 * * * pm2 restart mm.sh >/dev/null 2>&1
          #
          #SAMSTAG REBOOT UM 12:00 MAGICMIRROR REBOOT
          24 17 * * * sudo reboot
          #
          
          1 Reply Last reply Reply Quote 0
          • garblefluxG Offline
            garbleflux Project Sponsor
            last edited by

            @CyruS1337 said in Cronjob:

            Thanks for the link, but it still does not work :(

            # Edit this file to introduce tasks to be run by cron.
            #
            # Each task to run has to be defined through a single line
            # indicating with different fields when the task will be run
            # and what command to run for the task
            #
            # To define the time you can provide concrete values for
            # minute (m), hour (h), day of month (dom), month (mon),
            # and day of week (dow) or use '*' in these fields (for 'any').#
            # Notice that tasks will be started based on the cron's system
            # daemon's notion of time and timezones.
            #
            # Output of the crontab jobs (including errors) is sent through
            # email to the user the crontab file belongs to (unless redirected).
            #
            # For example, you can run a backup of all your user accounts
            # at 5 a.m every week with:
            # 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
            #
            # For more information see the manual pages of crontab(5) and cron(8)
            #
            # m h  dom mon dow   command
            #
            #MONTAG BIS SONNTAG UM 19:55 MAGICMIRROR RESTART
            55 19 * * * pm2 restart mm.sh >/dev/null 2>&1
            #
            #SAMSTAG REBOOT UM 12:00 MAGICMIRROR REBOOT
            24 17 * * * sudo reboot
            #
            

            Sounds strange. Maybe you first have to stop the pm2 process before restart, with pm2 stop mm.sh. Don’t forget to complete the line für den reboot am Samstag - sudo reboot >/dev/null 2>&1
            regards Michael

            1 Reply Last reply Reply Quote 0
            • M Offline
              MadScientist
              last edited by

              Why do you want to restart MM? Maybe pm2 reload mmis the better option.

              CyruS1337C 1 Reply Last reply Reply Quote 0
              • CyruS1337C Offline
                CyruS1337 Project Sponsor @MadScientist
                last edited by

                @MadScientist said in Cronjob:

                Why do you want to restart MM? Maybe pm2 reload mmis the better option.

                Why … that’s actually a good question. The problem is that if I bring the screens for about 5-6 hours and then turn back on that no picture appears on the monitors. Therefore, I would like a regular restart of my MagicMirros.

                1 Reply Last reply Reply Quote 0
                • M Offline
                  MadScientist
                  last edited by MadScientist

                  Are you using the GoogleMapsTraffic module? In that case the pm2 reload mm will do. Or a simple Ctrl+R on the mirror. The cronjob should then look something like 55 19 * * * pm2 reload mm (mine is 0 6 * * * pm2 reload mm and it works flawlessly).

                  CyruS1337C 2 Replies Last reply Reply Quote 0
                  • CyruS1337C Offline
                    CyruS1337 Project Sponsor @MadScientist
                    last edited by CyruS1337

                    @MadScientist said in Cronjob:

                    Are you using the GoogleMapsTraffic module? In that case the pm2 reload mm will do. Or a simple Ctrl+R on the mirror. The cronjob should then look something like 55 19 * * * pm2 reload mm (mine is 0 6 * * * pm2 reload mm and it works flawlessly).

                    Exactly, I use the modules GoogleMapsTraffi on these two monitors and these two monitors will not wake up after a while, if I turned off the monitors for several hours.

                    Then tonight I will try pm2 reload mm. Unfortunately, the command pm2 restart mm did not work. Then I’m curious.

                    1 Reply Last reply Reply Quote 0
                    • M Offline
                      MadScientist
                      last edited by

                      Depennding on the other modules you’re using it might be good to reload MM more than once a day. In my case once is enough. Without reloading the screen turns black after more than one day. Depending on your setup it could be better to reload it twice or 4 times a day. In the end the reload is very quick and you won’t notice anything.

                      1 Reply Last reply Reply Quote 0
                      • CyruS1337C Offline
                        CyruS1337 Project Sponsor
                        last edited by

                        Perfect, did not know that I can reload the MagicMirror. Have always made a restart in the past. I’ll give feedback this evening on whether the cronjob works with the pm2 reload mm command

                        1 Reply Last reply Reply Quote 0
                        • Z Offline
                          Zwirbel
                          last edited by Zwirbel

                          @MadScientist : Is there a way to automatically reload MM once or twice a day? I have similar problems with the Netatmo module, which doesn’t pick up new data in the morning (as my WLAN is turned off during the night). A reload fixes this, but I would rather have this automatically (e.g. at 06:00 in the morning for example).

                          Maybe a simple script would help, but I don’t know where to put it.

                          1 Reply Last reply Reply Quote 0
                          • CyruS1337C Offline
                            CyruS1337 Project Sponsor @MadScientist
                            last edited by

                            @MadScientist said in Cronjob:

                            55 19 * * * pm2 reload mm

                            The command works in the console pm2 reload mm

                            If I add it in the cron job, it will not do any reload.

                            Here is the excerpt from the crontab

                            # Edit this file to introduce tasks to be run by cron.
                            #
                            # Each task to run has to be defined through a single line
                            # indicating with different fields when the task will be run
                            # and what command to run for the task
                            #
                            # To define the time you can provide concrete values for
                            # minute (m), hour (h), day of month (dom), month (mon),
                            # and day of week (dow) or use '*' in these fields (for 'any').#
                            # Notice that tasks will be started based on the cron's system
                            # daemon's notion of time and timezones.
                            #
                            # Output of the crontab jobs (including errors) is sent through
                            # email to the user the crontab file belongs to (unless redirected).
                            #
                            # For example, you can run a backup of all your user accounts
                            # at 5 a.m every week with:
                            # 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
                            #
                            # For more information see the manual pages of crontab(5) and cron(8)
                            #
                            # m h  dom mon dow   command
                            #
                            #MONTAG BIS SONNTAG UM 17:02 MAGICMIRROR RELOAD
                            02 17 * * * pm2 reload mm
                            #
                            
                            
                            1 Reply Last reply Reply Quote 0
                            • M Offline
                              MadScientist
                              last edited by MadScientist

                              This is my crontab:

                              # daemon's notion of time and timezones.
                              #
                              # Output of the crontab jobs (including errors) is sent through
                              # email to the user the crontab file belongs to (unless redirected).
                              #
                              # For example, you can run a backup of all your user accounts
                              # at 5 a.m every week with:
                              # 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
                              #
                              # For more information see the manual pages of crontab(5) and cron(8)
                              #
                              # m h  dom mon dow   command
                              0 6 * * * pm2 reload mm
                              
                              
                              
                              

                              Are you running crontab -ewith sudo? Because you have to run it as the user that runs MM (= most likely without sudo).

                              Edit: @Zwirbel: For me it works using a cronjob. See what I wrote above and if you have questions regarding crontab, just ask again.

                              1 Reply Last reply Reply Quote 0
                              • CyruS1337C Offline
                                CyruS1337 Project Sponsor
                                last edited by

                                Juhuiiiii, finally it worked. Many Thanks

                                I have always used the command sudo crontab -e and with this it did not work.

                                It works fine with the crontab -e command and then 0 6 * * * pm2 reload mm

                                Once again, thank you very much for your help!!!

                                1 Reply Last reply Reply Quote 0
                                • M Offline
                                  MadScientist
                                  last edited by

                                  Glad it worked! :smiling_face_with_open_mouth:

                                  1 Reply Last reply Reply Quote 1
                                  • evroomE Offline
                                    evroom
                                    last edited by evroom

                                    @CyruS1337 said in Cronjob:

                                    I have always used the command sudo crontab -e and with this it did not work.

                                    Just to clarify.

                                    Normally you are user pi: $ who am I

                                    So crontab -e will work for the pi user.
                                    Using sudo crontab -e will change the crontab for the root user.

                                    Now how can you tell what is what ?

                                    For the user pi:
                                    $ sudo crontab -l -u pi
                                    which is the same as
                                    $ crontab -l
                                    For the user root:
                                    $ sudo crontab -l -u root

                                    Furthermore, when you have activated the root crontab, then the command will run as root, in the root (/) directory.
                                    In this case pm2 reload command will search for the mm.sh script under / and will not find it.
                                    Whereas when activated the pi crontab, the mm.sh script will be searched in the /home/pi directory, where it should be, and it will work.

                                    Use pm2 show mmto show the details on mm under pm2.
                                    Then you will understand it better.

                                    Cron messages normally are directed to /var/log/cron.log, but on my system it is not directed:

                                    $ grep cron /etc/rsyslog.conf
                                    #cron.*				/var/log/cron.log
                                    

                                    To see the cron messages, when not in cron.log:

                                    $ tail -F /var/log/syslog | grep CRON
                                    

                                    [ On my system I see CRON messages for root, although I do not have root crontab entries. There is a crond running that runs alongside $ systemctl status cron.]

                                    Have fun :-)

                                    MagicMirror version: 2.33.0
                                    Raspberry Pi 4 Model B Rev 1.5 (8 GB RAM)
                                    Raspbian GNU/Linux 12 (bookworm)

                                    Test environment:
                                    MagicMirror version: v2.33.0
                                    Raspberry Pi 3 Model B Plus Rev 1.3 (1 GB RAM)
                                    Raspbian GNU/Linux 12 (bookworm)

                                    CyruS1337C 1 Reply Last reply Reply Quote 2
                                    • CyruS1337C Offline
                                      CyruS1337 Project Sponsor @evroom
                                      last edited by

                                      @evroom Many thanks for the detailed information.

                                      As you can see, I always executed the command as sudo sudo crontab -e

                                      So I always executed the commands in the root directory. Which thus never led to success.

                                      Thanks again for the help and the detailed listing.

                                      Greeting

                                      1 Reply Last reply Reply Quote 0

                                      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                                      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                                      With your input, this post could be even better 💗

                                      Register Login
                                      • 1 / 1
                                      • First post
                                        Last post
                                      Enjoying MagicMirror? Please consider a donation!
                                      MagicMirror created by Michael Teeuw.
                                      Forum managed by Sam, technical setup by Karsten.
                                      This forum is using NodeBB as its core | Contributors
                                      Contact | Privacy Policy