Thread: scheduled running of a c file, checking date/time

  1. #1
    Registered User
    Join Date
    Nov 2003
    Posts
    3

    scheduled running of a c file, checking date/time

    I am using Redhat 9.0, gcc -

    I am trying to write a simple c application that:

    * starts when I turn the computer on
    * checks to see what time and day it is
    * if it is saturday, 8 p.m. it tells a different .c application to run

    I found bits and pieces in the forum to help me, but I am not quite sure where to start. I have a basic understanding of C, but I havn't done anything with background (stealth?) applications or date/time. And I have mostly used mac before, still new to linux.

    Thanks

  2. #2
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    you could make it a cron job.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Type this at the command prompt
    man crontab

    Example line
    00 20 * * Sat /path/to/my/saturday_program
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Nov 2003
    Posts
    3

    trying out cron...

    Thanks,

    cron certainly seems to be the way to go, but I am not getting it to work.

    I created a crontab for my user:
    15 10 * * * /src/hello/ a.out

    so at 10:15 I tried to run my c application called a.out that is in the path shown above. the test program just outputs the current time/date into the shell window, but nothing happened at 10:15.

    any suggestions?

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Well it won't output it to the current shell window - you may not even be logged in when cron runs

    By default, cron will send mail to your local account on your machine.

    If you want something in a specific file, then perhaps
    15 10 * * * /src/hello/a.out > /home/me/log.txt
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Aug 2002
    Posts
    351
    send your results to syslog within your C program.

    Then just grep for them when you want to check.

    Crond will send any data sent to stdout in a mail to the user who ran the cron job WHEN the program completes.

  7. #7
    Registered User
    Join Date
    Nov 2003
    Posts
    3

    cron working!

    Thanks everyone!
    Cron was working, just not seeing it. Tried to make a log.txt, but nothing was being written to it. But at some point, the shell told me I had new mail, which I went and checked, so cron is running my app.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  3. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  4. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM