Monday, September 16, 2024

Scheduler creations in Linux-based OS machines and Windows

Scheduler creations in Linux-based OS machines


Useful link for crontab calculations: https://crontab.guru/

To install crontab in Linux, you can use the following commands:

1. Update the package list: sudo apt update

2. Install cron: sudo apt install cron

3. Start the cron service: sudo systemctl start cron

4. Enable cron to start on system boot: sudo systemctl enable cron 

You can create a cron job by editing the /etc/crontab file. To do this, you can:

Open the crontab configuration file for the current user: crontab -e

Add a line containing a cron expression and the path to a script like below

*/5 * * * * /usr/bin/sh /home/narendra/my_stress_suite.bash > /home/taccuser/narendra/cron_jobs/abc.txt 2>&1

Save (Ctrl+x) and exit the crontab file 

Here are some special characters you can use in the time fields:

Asterisk (*): Specifies that the command should be run for every instance of the field

Hyphen (-): Can be used to indicate a range

Comma (,): Can be used to specify a list of values for a field

Forward slash (/): Can be used to specify step values 

You can also use shorthand extensions to replace the time fields. Some of these options include:

@reboot, @yearly, @annually, @monthly, @weekly, @daily, and @hourly


For shell scripts

*/5 * * * * /usr/bin/sh /home/narendra/my_stress_suite.bash > /home/taccuser/narendra/cron_jobs/abc.txt 2>&1

Explanation:

crontab -l   ==> Displays the contents of the crontab file associated with the current user on the screen

crontab -e   ==> By using this command we can modify the crontab configuration & save (Ctrl+x)

For python scripts

*/5 * * * * /usr/bin/python3 /home/narendra/my_stress_suite.py > /home/taccuser/narendra/cron_jobs/abc.txt 2>&1


Scheduler creations in Windows machines

truncate command in Linux is used to change the size of a file, either by shortening or extending itIt's a useful tool for managing file sizes and optimizing storage space

Syntax: truncate -s [number of bytes] filename_along_with_path

       Ex: truncate -s 0 narendra/cron_jobs/abc.txt

above command will delete the content of the file to make filesize 0 bytes (i.e, the file will present but data will be erased)


==============================================================

RequestIf you find this information useful, please provide your valuable comments.







No comments:

Post a Comment