ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Where am I supposted to add my cronjob?

    IT Discussion
    crontab cron cron job
    5
    7
    670
    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.
    • IRJI
      IRJ
      last edited by

      I used crontab -e to create a new cron job. Everything is working as expected, but I am looking to script this. Upon investigation of the location of the cron job, I find that it is located in /var/spool/cron/crotabs/userername .

      When I go down to the bottom of the file, I see my job as expected. So my thinking is to just write an echo to this file to add the job. However, the first commented paragraph is sort of confusing to me. It's telling my DO NOT EDIT THIS FILE and then it tells me to edit this file. Am I able to just create a new cron file in this folder and keep this one blank?

      # DO NOT EDIT THIS FILE - edit the master and reinstall.
      # (/tmp/crontab.plwseg/crontab installed on Fri May 24 09:10:21 2019)
      # (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)
      # 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
      
      1 Reply Last reply Reply Quote 0
      • IRJI
        IRJ
        last edited by

        This guy asks the same question as me and the response he get is that it is ok to do this. Why is that first line there, though?

        https://serverfault.com/questions/347318/is-it-bad-to-edit-cron-file-manually#347321

        DustinB3403D 1 Reply Last reply Reply Quote 0
        • DustinB3403D
          DustinB3403 @IRJ
          last edited by

          @IRJ said in Where am I supposted to add my cronjob?:

          This guy asks the same question as me and the response he get is that it is ok to do this. Why is that first line there, though?

          https://serverfault.com/questions/347318/is-it-bad-to-edit-cron-file-manually#347321

          I would think this is stated to get you to make a backup of this file before making edits.

          wirestyle22W 1 Reply Last reply Reply Quote 0
          • wirestyle22W
            wirestyle22 @DustinB3403
            last edited by

            @DustinB3403 said in Where am I supposted to add my cronjob?:

            @IRJ said in Where am I supposted to add my cronjob?:

            This guy asks the same question as me and the response he get is that it is ok to do this. Why is that first line there, though?

            https://serverfault.com/questions/347318/is-it-bad-to-edit-cron-file-manually#347321

            I would think this is stated to get you to make a backup of this file before making edits.

            Yeah it reads that way

            1 Reply Last reply Reply Quote 0
            • ObsolesceO
              Obsolesce
              last edited by Obsolesce

              Very odd that the only way to script a cron job is to edit that file. Definitely a big negative.

              Surely there is a much better way. I've never had to edit that file to script a cron job. What are you doing?

              IRJI 1 Reply Last reply Reply Quote 0
              • IRJI
                IRJ @Obsolesce
                last edited by

                @Obsolesce said in Where am I supposted to add my cronjob?:

                Very odd that the only way to script a cron job is to edit that file. Definitely a big negative.

                Surely there is a much better way. I've never had to edit that file to script a cron job. What are you doing?

                Checking on a service

                1 Reply Last reply Reply Quote 0
                • stacksofplatesS
                  stacksofplates
                  last edited by

                  If this is a systemd distro, you can just create a timer and service. That way instead of sending a mail message, it's automatically part of the logging for that unit.

                  If it's a recent version of systemd, you can have a user based systemd that doesn't need escalated privileges. I just finished setting up borg for backup since I'm on Fedora Silverblue now (couldn't use the old way), and I just set up user based systemd units to do the backup.

                  1 Reply Last reply Reply Quote 2
                  • 1 / 1
                  • First post
                    Last post