skip to Main Content

I’ve got a C# asp.net core app running on an Ubuntu box. I need to run some scheduled tasks and wanted some way to manage that from the app, rather than logging into a terminal.

Is there anyway the C# app can connect to cron and return current jobs, add / edit existing ones?

2

Answers


  1. Best bet is to expand on the following code:

        Process process = new System.Diagnostics.Process ();
    
        Process proc = new System.Diagnostics.Process ();
        proc.StartInfo.FileName = "/bin/bash";
        proc.StartInfo.Arguments = "-c " " + command + " "";
        proc.StartInfo.UseShellExecute = false; 
        proc.StartInfo.RedirectStandardOutput = true;
        proc.Start();
    

    This will get you started with executing bash commands and reading the output in your code.

    Alternatively, as Tristan mentioned in the comments, you can certainly read/write the cron files from your code as well.

    Login or Signup to reply.
  2. Not a direct answer but if you want a controllable scheduled tasks you can consider using hosted services to perform background tasks or libraries/frameworks like Hangfire or Quartz.NET.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search