Task Scheduling in Linux - CronTab Command and How to Create/Use a Cron Job

Sdílet
Vložit
  • čas přidán 2. 08. 2024
  • Task Scheduling in Linux using CronTab Command to create and use Cron Jobs for executing commands periodically. This video will show you how to use/create a Cron Job using the CronTab Command on Linux and Schedule a Task to run at some given interval. Use this CronTab Command to Schedule multiple tasks and checkout the syslog for information about the task running on Ubuntu.
    The reason to learn about cron is because it’s a time-based scheduling utility that allows you to schedule various jobs/tasks to run periodically or even on special system events. It’s fairly easy to use and comes with most Linux Based Distributions. Instead of having to daemonizie a task/process you can simply just make a call to it using Cron.
    My Linux Cheat Sheet and 25 Page Checklist here:
    📚 learn.savvynik.com
    Share this free tool and support Small CZcamsrs
    editbulk.com
    (I made this tool to help creators)
    Want more info/content?
    savvynik.com
    📺Top/Latest Videos:
    Setup and Use Visual Studio Code on Linux (C++) - • C++ Tutorial for Begin...
    Install Windows Programs on Ubuntu 20.04 (wine) - • How to Run Windows Pro...
    Kali Linux Install Tutorial - • Kali Linux Install Tut...
    Parrot OS Security 4.9 Install Tutorial - • Parrot OS 4.9 Linux In...
    Terminal Absolute Basics for Beginners - • Linux Absolute Basics ...
    Bash Shell Scripting Reading User Input - • Bash Shell Scripting T...
    Ubuntu 20.04 Updates & 18.04 Comparison - • Ubuntu 20.04 Linux | N...
    Ubuntu 20.04 Install Tutorial - • Ubuntu 20.04 LTS Linux...
    Pop OS 20.04 Updates - • Pop OS 20.04 (BETA) Li...
    C++ Episode #10 Debugging w/ VSCode - • C++ Tutorial for Begin...
    Debian 10 Buster Install Tutorial - • Debian 10 Buster Insta...
    Arch Linux Dual Boot with Windows 10 - • Arch Linux Install (UE...
    Linux Mint Install Tutorial - • Linux Mint Install 19....
    Fedora Install Tutorial - • Fedora 31 Workstation ...
    CentOS 8 Install Tutorial - • CentOS 8 Install Linux...
    __
    Useful Links/Commands:
    Discord: / discord
    Gnome Terminal Icon
    By gitlab.gnome.org/jimmac - gitlab.gnome.org/GNOME/gnome-..., GPLv3, commons.wikimedia.org/w/index...
    #linux #linuxtutorial #savvytip
    0:00 - Explaining what Cron Is
    0:55 - Installing Cron if not already available
    1:15 - Crontab -e command (editor)
    1:42 - How to change Crontab editor
    2:12 - Setting up our first CronTab
    3:44 - How the scheduling in CronTab works
    5:38 - Checking if CronTab is running in Logs
    6:43 - An example of a command getting executed every minute
    7:30 - CronTab on Reboot Example
    8:00 - CronTab running a Bash Script
    8:46 - CronTab List Command
    9:00 - How to get detailed logs of tasks in Cron
    10:00 - CronTab with Specific User
    10:30 - Checking out our New Running Task
    11:05 - Outro
    Make sure to Subscribe below for Future Installs, Updates, Reviews, and Tips!!!
  • Věda a technologie

Komentáře • 53

  • @tuxmaster2715
    @tuxmaster2715 Před 3 lety +3

    Thanks bud, this was greatly explained, I got everything.
    Keep ipt up, such great content!

    • @SavvyNik
      @SavvyNik  Před 3 lety +2

      Awesome to hear! Glad you enjoyed it. No problem and make sure to smash that like button for me if you haven't already =)

  • @Douglas-hw8is
    @Douglas-hw8is Před 2 lety +1

    Excellent tutorial - many thanks.

    • @SavvyNik
      @SavvyNik  Před 2 lety

      You are welcome! Glad you liked it.

  • @technatrix2506
    @technatrix2506 Před 2 lety +1

    Very valuable video, Keep up the nice work

  • @jig1056
    @jig1056 Před 2 lety +1

    Very nice video. Thanks

  • @SavvyNik
    @SavvyNik  Před 4 lety +1

    Timestamps in the description!

  • @behindthescene2727
    @behindthescene2727 Před 2 lety +1

    made easy

  • @zeeshanahmed3997
    @zeeshanahmed3997 Před 3 lety +1

    Very informative!!
    Can we run a particular application (setting the script file: that notes the execution time of application being run) but non periodically like when we launch application it records the time duration of an application being running.? Thanks

    • @SavvyNik
      @SavvyNik  Před 3 lety

      You might want to check out a supervisor daemon instead that can monitor and execute processes - czcams.com/video/eX7D40y9qv8/video.html

  • @lets_learn_some_tech5542
    @lets_learn_some_tech5542 Před 4 lety +2

    Nice 👍👍
    It would be nice if you could do anything about the audio, it seems to have a robot talking kind of noise.

    • @SavvyNik
      @SavvyNik  Před 4 lety

      @sameer Kumar - Yeah, I'm working on trying to make better! I think it's because of the echo in the room. Need some soundproofing foam maybe.

  • @TFCSDCzyTheFlyingCockroach

    how to use crontab to run chrome with different profile that i created?

  • @_CIVIL__NISARAHMEDMD
    @_CIVIL__NISARAHMEDMD Před 2 lety

    Determine the status of the service related to scheduling. Store the status in a file (/tmp/service).
    Eg. If the service is running, store the value as active. If the service is not running, store the value as inactive.
    can you please help in this..i need answer..

  • @rubi17able
    @rubi17able Před 3 lety

    can we add an exe file to it, and how

  • @CodyCLI
    @CodyCLI Před 3 lety +1

    I want to set an update script to a cron jobm could I enter this command
    "sudo apt update && sudo apt upgrade && sudo apt autoremove && sudo apt autoclean"
    Could I just enter that into cron, or would that mess things up, idk if I have to do sudo.

    • @SavvyNik
      @SavvyNik  Před 3 lety

      Here's an example on how you would do this with Ubuntu - help.ubuntu.com/community/AutoWeeklyUpdateHowTo you can use && but you may have to call aptitude (apt) directly from its absolute path on the system. I would suggest putting everything in a bash script and then calling the bash. Sort of like I do in this vid - czcams.com/video/t_xgSr6z2Ks/video.html

  • @bonkzbajaro7414
    @bonkzbajaro7414 Před 2 lety

    @savvynik I am just a novice in linux, can you help me create a cronjob in monitoring my computer in the office if still online using the ping test, say example every hour, and create a txt log file of the ping result in the same pc-folder (my assignment). thanks a lot.

  • @drewmalbica7694
    @drewmalbica7694 Před 3 lety +1

    Hey I’ve got a question. I have been successfully running one cron job backing up my Minecraft world once a day. Well I started a second world hosted on the same machine and I made another script for backing up that world and when I added it to the crontab, it isn’t running and when I run systemctl status cron, it says I only have one job. Any ideas on how I can get 2 jobs to work?

    • @SavvyNik
      @SavvyNik  Před 3 lety

      You should be able to just add another line. More than likely there's something wrong with the path to the second script or perhaps a permissions issue (cmod). The last thing you could try is if they run at the same interval you can execute both on the same crontab line.. (* * * * * /path/to/script1.sh && /path/to/script2.sh) then finally make sure to destroy that like button for me ;)

    • @drewmalbica7694
      @drewmalbica7694 Před 3 lety +1

      @@SavvyNik ok I’ll try adding them to one line. The scripts are in the same directory. They work if you run them manually. I noticed I had &> /dev/null at the end of the first line. I’m not sure what that does but when I had just one job on my cron it worked.

    • @drewmalbica7694
      @drewmalbica7694 Před 3 lety

      I liked and Sub’d your vid was one of the easier ones to follow that I’ve seen.

    • @SavvyNik
      @SavvyNik  Před 3 lety

      @@drewmalbica7694 well great. /dev/null is a special system file that when written to (ask your doing) will disregard all that is written. Sounds like you figured things out either way. Congrats and smash that like button for me if you haven't already.

  • @budinaga5869
    @budinaga5869 Před 3 lety +1

    I liked the video and sub. thanks
    But how do i backup a file. For example I want to backup a txt file from my dekstop everyday at 11pm?
    thanks

    • @SavvyNik
      @SavvyNik  Před 3 lety

      You're welcome. Glad you found the video helpful. I would run a compression of the file and store it somewhere on a networked drive / external drive by copying it over. I think if you google a little there are plenty of people who've backed up folders / files before using cronjobs/tabs.

  • @Thesoulfire
    @Thesoulfire Před 3 lety +1

    Is it possible to have 3 things to happen on reboot.
    1. Wipe Ssd
    2. Clear trash
    3. Run .sh
    If so will I stack them in the order I want it the happen?

    • @SavvyNik
      @SavvyNik  Před 3 lety +1

      Sure you could do something like this.. I'm not sure what you would want to "wipe" an ssd. Here's an example of cleaning out the trash: czcams.com/video/t_xgSr6z2Ks/video.html

    • @Thesoulfire
      @Thesoulfire Před 3 lety +1

      I am plotting for chia network and if my NUC reboots I need clear my nvme of the temp files that were left from behind when plotting was interrupted.

  • @dilipverma9217
    @dilipverma9217 Před 2 lety

    Hello sir,How can configure crontab to run a script
    Second saturday will be execute at 5 AM
    and other all saturday will be execute at 5 PM
    Please help me sir
    Thanks in advance

  • @jaryalbhau
    @jaryalbhau Před 4 lety +1

    Pls provide me codeigniter crontab url when i execute controller mathod function in crontab

    • @SavvyNik
      @SavvyNik  Před 4 lety +1

      @Singh JARYAL - Take a look at this example stackoverflow.com/questions/19269566/how-to-set-cron-job-url-for-codeigniter

    • @jaryalbhau
      @jaryalbhau Před 4 lety +1

      I got it
      * * * * * /usr/bin/php /home/username/public_html/index.php controller_name/controller_method

    • @SavvyNik
      @SavvyNik  Před 4 lety +1

      @@jaryalbhau - Awesome!! Glad it worked out for you =) make sure to destroy that like button for me on the video if you haven't already.

  • @thek6231
    @thek6231 Před 2 lety

    How to stop cron job before boot up the ubuntu operating system. I scheduled cronjob like this * * * * * shutdown now. How can I stop this job.

  • @azimfakhri6320
    @azimfakhri6320 Před 4 lety +1

    can you please show me how to set a cron job so it can automatically mount the USB in every 1 mint ?

    • @SavvyNik
      @SavvyNik  Před 4 lety +1

      * * * * * mount /dev/ / for example * * * * * mount /dev/sdc1 /mnt - of course replace the two with your device name and place you want to mount the device to. That should be enough to get you going =)

    • @azimfakhri6320
      @azimfakhri6320 Před 4 lety +1

      @@SavvyNik thanks for the reply, in my case i have 2 USB with same LABEL, so should i just right it like this : * * * * * /dev/Intenso /mnt/usb-backups

    • @azimfakhri6320
      @azimfakhri6320 Před 4 lety

      @@SavvyNik i also need to say that i mounted the USBs with LABELS not names or UUID

    • @SavvyNik
      @SavvyNik  Před 4 lety +1

      ​@@azimfakhri6320 - Each usb should get it's own device name. There shouldn't be repeated device names. I would check the /dev folder with one usb plugged in and plug in the second one and watch for a change in /dev. You should see something like sdb1 and sdc1 not Intenso also not sure why you would do usb-backups unless you created a new folder called that in your /mnt directory. All mount does is mounts a device to a specific folder. If you want to copy something into that folder you would do cp /mnt//

    • @azimfakhri6320
      @azimfakhri6320 Před 4 lety +1

      @@SavvyNik Im using ProxMox VM and i wanted to have a backup of my Vms, that is why i was thinking i will do the same thing with our customers, so 2 USBs with under the same LABEL so when i swap the USBs or the customer do it themselvs, the system does not know that the USB is disconnected, i was thinking to make a Cron Job for Auto mounting USB drive and the time would be 1 mint, after each 1 mint, the system will look for USB to do the backup, 1 mint because we dont know when we are going to swap the USBs.
      i made usb-backups and mounted my USBs into this folder, the backup is also there, but when i change the USB i have to mount it manually.
      hope i putted a bit of light on what im planning to do.
      Peace

  • @mohamedrafiyudeent3162

    How to create a custom cron job in Linux

  • @JamesSamples
    @JamesSamples Před 3 lety

    LOL, Why did:
    59 * * * * rm -rf /home/james/.local/share/Trash/files/*
    delete all my files?

    • @SavvyNik
      @SavvyNik  Před 3 lety

      maybe in your trash bin ??

    • @JamesSamples
      @JamesSamples Před 3 lety +1

      @@SavvyNik
      I was actually playing around and did:
      1 * * * * rm -rf /home/james/.local/share/Trash/files/*
      2 * * * * rm -rf /home/james/.local/share/Trash/files/*
      and continued to:
      59 * * * * rm -rf /home/james/.local/share/Trash/files/*
      I had everything backed up so it wasn't a big deal. It wiped away my Documents Folder, Pictures, Downloads,.... it left the os intact.
      IDK. ?

    • @SavvyNik
      @SavvyNik  Před 3 lety +1

      One way I could think of that happening is if you had a space between /home/ and .local. That would delete the contents of an entire user directory. Got to be careful with those rm commands =D
      Well I'm glad you got things working!!