This package will help create, get and edit tasks in your system's crontab.
$ dotnet add package BinaryCoffee.SchedulingTaskCrontab is a task scheduling tool on Unix and Linux operating systems that allows for programming the execution of commands at specific times, either repeatedly or at a one-time occurrence.
The basic syntax of a Crontab command consists of five fields separated by spaces that define the time of execution:
For example:
0 12 * * *
This command will execute a task every day at 12:00 PM.
Crontab simplifies system administration and automates routine tasks, making workflows more efficient.
BinaryCoffee.ScheduleYourTask is a .NET package that brings the power of Crontab scheduling to the .NET platform. It enables developers to interact with crontab configurations programmatically.
Include the package in your project: Install from NuGet: BinaryCoffee.ScheduleYourTask
Declare the namespace:
using SchedulingTasks;
Access the functionality:
Use methods like Crontab.GetCrontab() to interact with crontab entries programmatically.
using SchedulingTasks;
// Retrieve existing tasks
var tasks = Crontab.GetCrontab();
Console.WriteLine("Current Crontab Entries:");
Console.WriteLine(tasks);
using SchedulingTasks;
// Add a new task to run a script daily at 2 AM
string task = "0 2 * * * /path/to/your/script.sh";
Crontab.AddTask(task);
Console.WriteLine("Task added successfully.");
using SchedulingTasks;
// Remove a task using its unique identifier
string taskIdentifier = "your-unique-identifier";
Crontab.RemoveTask(taskIdentifier);
Console.WriteLine("Task removed successfully.");
using SchedulingTasks;
// Enable a task
string taskIdentifier = "your-unique-identifier";
Crontab.EnableDisableTask(taskIdentifier, true);
Console.WriteLine("Task enabled successfully.");
// Disable a task
Crontab.EnableDisableTask(taskIdentifier, false);
Console.WriteLine("Task disabled successfully.");
using SchedulingTasks;
// Export crontab configuration to a file
string filePath = "/path/to/exported_crontab.txt";
Crontab.ExportTasks(filePath);
Console.WriteLine($"Crontab exported to {filePath}.");
using SchedulingTasks;
// Import tasks from a file
string filePath = "/path/to/imported_crontab.txt";
Crontab.ImportTasks(filePath);
Console.WriteLine("Crontab imported successfully.");
using SchedulingTasks;
// Track changes to crontab
Crontab.TrackCrontabChanges();
Console.WriteLine("Crontab changes tracked and backup created.");
Crontab.GetCrontab():
Retrieves the current crontab configuration.
Crontab.AddTask(string task):
Adds a new task to the crontab.
Crontab.RemoveTask(string taskIdentifier):
Removes a task by its unique identifier.
Crontab.EnableDisableTask(string taskIdentifier, bool enable):
Enables or disables a task by toggling comments.
Crontab.ExportTasks(string filePath):
Exports the crontab configuration to a file.
Crontab.ImportTasks(string filePath):
Imports tasks from a crontab file.
Crontab.TrackCrontabChanges():
Tracks changes to crontab by creating timestamped backups.
Feel free to contribute by submitting issues or pull requests to the GitHub Repository.
Made with ☕ by BinaryCoffee.