How To Write Bash Scripts In Linux - Complete Guide (Part 14 - Scheduling Jobs)

How To Write Bash Scripts In Linux - Complete Guide (Part 14 - Scheduling Jobs)

Introduction to Scheduling Jobs in Bash Scripting

Overview of the Series

  • The video is part of a bash scripting series focused on scheduling jobs, with this being part one of two.
  • The presenter expresses excitement about teaching viewers how to run scripts at specific times.

Importance of Scheduling Scripts

  • As scripts become more complex, there arises a need to schedule them for execution at later times, such as overnight or over weekends.
  • The goal is to automate script execution without manual intervention.

Installing the at Command

Checking Availability

  • The presenter checks if the at command is available on their system and finds it missing.
  • It’s noted that users should be logged into the server where they want to execute commands.

Installation Process

  • To install at, the command sudo apt install at is used; users may need different package managers based on their distribution.
  • Installation is quick since at is a small utility. After installation, it becomes ready for use.

Creating a Simple Script for Demonstration

Script Creation

  • A simple script is created that logs output into a file named jobresults.log. This serves as an example for using the at command.
  • The script includes an echo statement that records when it runs, demonstrating basic functionality rather than complexity.

Testing the Script

  • Before scheduling, the script is executed manually to ensure it works correctly; results are verified by checking the log file contents.

Scheduling Jobs with the at Command

Using the Command

  • The presenter schedules a job using at, specifying 3:32 PM as the time for execution after confirming current time (3:29 PM).

Job Confirmation

  • After waiting until 3:32 PM, it's confirmed that the job ran successfully as indicated by creation of jobresults.log.

Understanding Job Management with at

Viewing Scheduled Jobs

  • To view scheduled jobs, the command atq (queue of jobs) is used; it shows job IDs and scheduled times.

Deleting Scheduled Jobs

  • If needed, jobs can be canceled using atrm <job_id>, which removes them from the queue and confirms successful deletion by rechecking with atq.

Advanced Usage and Conclusion

Future Scheduling Examples

  • An example demonstrates scheduling a job far in advance (August 16th), showcasing flexibility in setting dates and times for future executions.

Summary of Learning Outcomes

  • Viewers are encouraged to experiment with scheduling jobs using the at command before moving on to part two of this topic in subsequent lessons.
Video description

Learn how to schedule one-time tasks with the at command in Linux! In this episode of the Bash scripting course from LearnLinuxTV, you’ll discover how to use the at command to schedule future tasks with precision. Whether you need to run a script later today or at a specific time tomorrow, this video will walk you through practical examples to help you automate time-based commands effectively. *📖 Check out my brand-new Linux Troubleshooting eBook!* Contains expert strategies to help you level-up your System Administration game. Packed with advice, best practices as well as some Linux-related life hacks! - Check it out here ➜ https://learnlinux.link/troubleshooting-ebook *📖 Check out my brand-new Linux Troubleshooting eBook!* Contains expert strategies to help you level-up your System Administration game. Packed with advice, best practices as well as some Linux-related life hacks! - Check it out here ➜ https://learnlinux.link/troubleshooting-ebook ━━━━━━━━━━━━━━━━━━━━━━ *❤️ Support the Channel and Get Awesome Stuff* Books, discounts, shirts and more! - Switching to Linux Book (New!) ➜ https://learnlinux.link/switch-to-linux - Ansible Course ➜ https://learnlinux.link/ansible - Linux Essentials Course ➜ https://learnlinux.link/linux-essentials - eBook Bundle ➜ https://learnlinux.link/ebook-bundle - Linux Merch Shop ➜ https://merch.learnlinux.tv - Linode Starter Credit ➜ https://learnlinux.link/linode - Paid Assistance ➜ https://www.learnlinux.tv/request-assistance *❤️ Support the Channel* - Enjoyed the video? Your support keeps this channel independent! - Become a Channel Member (Ad-Free & Early Access) ➜ https://learnlinux.link/join - Support on Patreon ➜ https://learnlinux.link/patron ━━━━━━━━━━━━━━━━━━━━━━ 🕐 Time Codes 00:00 - Intro 00:46 - Why would you want to schedule scripts to run later? 02:00 - Installing the "at" command in Linux 03:01 - Creating an example Bash Script for today's lesson 05:13 - Scheduling a job with the at command 08:15 - Managing "at" jobs with the atq and atrm commands 09:13 - Additional examples of using the "at" command *OTHER BASH SCRIPTING SERIES EPISODES* - Class 01 ➜ Introduction: https://linux.video/bash1 - Class 02 ➜ Hello World: https://linux.video/bash2 - Class 03 ➜ Variables: https://linux.video/bash3 - Class 04 ➜ Math Functions: https://linux.video/bash4 - Class 05 ➜ If Statements: https://linux.video/bash5 - Class 06 ➜ Exit Codes: https://linux.video/bash6 - Class 07 ➜ While Loops: https://linux.video/bash7 - Class 08 ➜ Universal Update Script: https://linux.video/bash8 - Class 09 ➜ For Loops: https://linux.video/bash9 - Class 10 ➜ Where To Store Your Scripts: https://linux.video/bash10 - Class 11 ➜ Data Streams: https://linux.video/bash11 - Class 12 ➜ Functions: https://linux.video/bash12 - Class 13 ➜ Case Statements: https://linux.video/bash13 - Class 14 ➜ Scheduling Jobs (Part 1): https://linux.video/bash14 - Class 15 ➜ Scheduling Jobs (Part 2): https://linux.video/bash15 - Class 16 ➜ Arguments: https://linux.video/bash16 - Class 17 ➜ Building a Backup Script: https://linux.video/bash17 - Class 18 ➜ Closing: https://linux.video/bash18━━━━━━━━━━━━━━━━━━━━━━ *🎓 Learn Linux TV* Your source for Linux-related Fun and Learning! https://www.learnlinux.tv https://community.learnlinux.tv https://learnlinux.link/jay ━━━━━━━━━━━━━━━━━━━━━━ *🤝 Affiliate Notice* Some of the links mentioned in this description are affiliate links. If you purchase through them, it helps keep the content flowing. https://www.learnlinux.tv/content-ethics *⚠️ Disclaimer* Learn Linux TV produces technical content that will hopefully be helpful to you and teach you something new. However, this content is provided without any warranty (expressed or implied). Learn Linux TV is not responsible for any damages that may arise from any use of this content. #linux #linuxtutorial #bash