How would one go about scheduling a C program to execute at a certain time, then email the output to someone upon completion? I'm personally working in ubuntu, but even a general answer would be great (if using ubuntu matters or not).

Could the same be done in a C++ program? And if so, are there really any differences in how it would be implemented?

  • 3
    The language that the program is written in has nothing to do with this. – Kusalananda May 11 '18 at 6:48

The way to exec program (independently of the nature) is sample. You need a compiled program i.e. executable file. And the you need to add record to the cron. The record can be something like:

10 5 * * * /path/to/your/program

The above will execute program located in directory /path/to/your at 05:10 If you want to send mail and this functionality is not incorporated in your program you can create shell script where exec your program, redirect output to file (real or virtual) and send mail.

  • 1
    No need to add a script to send email, cron will do that for you. – Stephen Kitt May 11 '18 at 5:18
  • 1
    @StephenKitt, right, but only if you run the cron with the same user as mail recipient :) – Romeo Ninov May 11 '18 at 5:20
  • 2
    Not necessarily, you can use MAILTO to specify an email address and the cron result will be sent there. – Stephen Kitt May 11 '18 at 5:21
  • @StephenKitt With the caveat that MAILTO is global to a user crontab, if you want multiple email destinations you might want to mail the stdout of the scripts. – Rui F Ribeiro May 11 '18 at 7:32
  • 1
    Of course, the word at is in the question. (-: – JdeBP May 11 '18 at 7:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.