Results 1 to 4 of 4

Thread: Adding a cron job through a script (UNIX)

  1. #1
    Taz
    Taz is offline
    Senior Member Taz's Avatar
    Join Date
    Jan 2005
    Location
    London
    Posts
    2,117
    Thanks
    55
    Thanked
    26 times in 25 posts
    • Taz's system
      • Motherboard:
      • Gigabyte Z270 HD3P
      • CPU:
      • Intel Core i5 7600K
      • Memory:
      • Corsair CMK16GX4M2B3200C16R Vengeance LPX 16 GB
      • Storage:
      • Samsung 960 EVO M.2-2280 500GB (PCIe) + 1TB Sandisk Ultra II SSD (SATA)
      • Graphics card(s):
      • Asus NVIDIA GeForce GTX 1070 OC
      • PSU:
      • Corsair CS550M 550W Hybrid
      • Case:
      • NZXT Source 340
      • Operating System:
      • Windows 10 Pro
      • Monitor(s):
      • 34" Asus Designo Curve MX34VQ UWQHD Monitor
      • Internet:
      • Virgin Media Vivid 200

    Adding a cron job through a script (UNIX)

    I would like to be able to add a cron entry (for 'root') simply by running a shell script. What I would like to avoid is having to use 'crontab -e' and editing the entry into the list of existing entries. I simply want to add a new cron job at the end of the current list.

    The cron entry would look something like this:

    Code:
    3 * * * * /<path>/<myscript.sh> <argument>
    The slight twist to this requirement is that the script I want executed at 3.00am every day requires an argument so I need to be able to pass the argument to it too (from the cron job).

  2. #2
    Comfortably Numb directhex's Avatar
    Join Date
    Jul 2003
    Location
    /dev/urandom
    Posts
    17,074
    Thanks
    228
    Thanked
    1,027 times in 678 posts
    • directhex's system
      • Motherboard:
      • Asus ROG Strix B550-I Gaming
      • CPU:
      • Ryzen 5900x
      • Memory:
      • 64GB G.Skill Trident Z RGB
      • Storage:
      • 2TB Seagate Firecuda 520
      • Graphics card(s):
      • EVGA GeForce RTX 3080 XC3 Ultra
      • PSU:
      • EVGA SuperNOVA 850W G3
      • Case:
      • NZXT H210i
      • Operating System:
      • Ubuntu 20.04, Windows 10
      • Monitor(s):
      • LG 34GN850
      • Internet:
      • FIOS

    Re: Adding a cron job through a script (UNIX)

    most systems include a file "/etc/crontab", which is a kind of easily-found always-ready master cron file. i'd use that.

    more modern systems have /etc/cron.d where you can place cron snippets that are managed by the main /etc/crontab - that way you can put a symlink to a file in your app's folder, rather than editing system config files. if that folder exists, it's a better bet, but no promises that it exists

  3. #3
    Taz
    Taz is offline
    Senior Member Taz's Avatar
    Join Date
    Jan 2005
    Location
    London
    Posts
    2,117
    Thanks
    55
    Thanked
    26 times in 25 posts
    • Taz's system
      • Motherboard:
      • Gigabyte Z270 HD3P
      • CPU:
      • Intel Core i5 7600K
      • Memory:
      • Corsair CMK16GX4M2B3200C16R Vengeance LPX 16 GB
      • Storage:
      • Samsung 960 EVO M.2-2280 500GB (PCIe) + 1TB Sandisk Ultra II SSD (SATA)
      • Graphics card(s):
      • Asus NVIDIA GeForce GTX 1070 OC
      • PSU:
      • Corsair CS550M 550W Hybrid
      • Case:
      • NZXT Source 340
      • Operating System:
      • Windows 10 Pro
      • Monitor(s):
      • 34" Asus Designo Curve MX34VQ UWQHD Monitor
      • Internet:
      • Virgin Media Vivid 200

    Re: Adding a cron job through a script (UNIX)

    directhex, I need to make the script relatively portable across most corporate flavours of UNIX. Also, if I edit /etc/crontab then I would have to send an INIT signal to cron itself for it to re-read the /etc/crontab (I think!).

  4. #4
    Comfortably Numb directhex's Avatar
    Join Date
    Jul 2003
    Location
    /dev/urandom
    Posts
    17,074
    Thanks
    228
    Thanked
    1,027 times in 678 posts
    • directhex's system
      • Motherboard:
      • Asus ROG Strix B550-I Gaming
      • CPU:
      • Ryzen 5900x
      • Memory:
      • 64GB G.Skill Trident Z RGB
      • Storage:
      • 2TB Seagate Firecuda 520
      • Graphics card(s):
      • EVGA GeForce RTX 3080 XC3 Ultra
      • PSU:
      • EVGA SuperNOVA 850W G3
      • Case:
      • NZXT H210i
      • Operating System:
      • Ubuntu 20.04, Windows 10
      • Monitor(s):
      • LG 34GN850
      • Internet:
      • FIOS

    Re: Adding a cron job through a script (UNIX)

    i think /etc/crontab is reread by cron all the time, so no need to restart the daemon (that's certainly the case on this ubuntu machine, i don't have any unix systems anymore to test with their daemons)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 14
    Last Post: 17-05-2008, 12:24 PM
  2. Trying to get a cron job working on qiq.co.uk
    By Whiternoise in forum Software
    Replies: 11
    Last Post: 03-10-2007, 09:30 AM
  3. Cron Job Problems
    By Matt1eD in forum Software
    Replies: 4
    Last Post: 19-02-2006, 01:00 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •