Thread: cron and c.out

  1. #16
    Registered User
    Join Date
    Jun 2019
    Posts
    44
    Salem, why is your txt files inside crontabs? Should it be the other way around? Was there a problem with cron running all three of your c-files inside cron like it does for script and batchs? Whatever the case it did something and I did not know it could work that way. IÂ’m going to make some changes to my files and see what happen. Wow, cron running text files.

    And also why are your numbers being incremented so high. It's suppose to increase by one each day or every 1-5 minutes during testing. My code had the same problem. The first file incremented by 1 properly but the other two either did nothing or it would increase by a much higher numbers with is not what the code I posted was even design to do. It just did it anyway. So that is cron fault, correct?

    I can't wait to try the txt file thing. Time to clean up my mess and reboot

  2. #17
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by jc2020
    why is your txt files inside crontabs? Should it be the other way around?
    The text files aren't inside the crontab. Rather, each filename is supplied as a command line argument to the program that is executed via cron, hence they appear in the crontab after the program name.

    Quote Originally Posted by jc2020
    And also why are your numbers being incremented so high. It's suppose to increase by one each day or every 1-5 minutes during testing. (...) So that is cron fault, correct?
    This is where the crontab.guru tool comes in handy if you're like me: either too lazy to even parse the syntax yourself, or like to second guess yourself in case of misinterpretation so you want a tool to check it for you.

    The tool will tell you that these:
    Code:
    */5 * * * *
    */10 * * * *
    */15 * * * *
    respectively mean:
    Code:
    At every 5th minute.
    At every 10th minute.
    At every 15th minute.
    Now, we see that counter1.txt starts at 13 and ends up at 68. 68 - 13 = 55. So we know that the program was run 55 times to update counter1.txt. Since the cronjob is set to run the program at every 5th minute, and the program increments the counter each time it is run, it follows that about 55 * 5 = 275 minutes have elapsed.

    Now, 275 / 10 = 27.5. Observe that for counter2.txt, we started at 6 and ended at 34. 34 - 6 = 28, which is consistent with the approximation of 27.5. Likewise, 275 / 15 ~= 18.3. For counter3.txt, we have 23 - 5 = 18, which again is consistent.

    In conclusion, cron worked exactly as it should have. It isn't cron's fault, and if you wrote the crontab correctly, it isn't your fault in setting up the cronjob either. This means that the fault might lie with the programs that are being executed via cron.
    Last edited by laserlight; 03-15-2020 at 11:21 PM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #18
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    Quote Originally Posted by laserlight View Post
    In conclusion, cron worked exactly as it should have. It isn't cron's fault, and if you wrote the crontab correctly, it isn't your fault in setting up the cronjob either. This means that the fault might lie with the programs that are being executed via cron.
    That just circles back to my point that the number isn't being overwritten correctly, jc, for clarity I mean something like this example in the case addTo was made to just return num + 1

    The text file would start with the value "1", then it would become "12" then it would become "1213" then it would become "12131214", etc etc

    If your intent is to override the value then you need to push the file offset back to the start and write from there, but you also must make sure the number ends at either EOF or a whitespace character so that fscanf does not treat any remaining digits from the previous number as if it were part of the intended number, the best thing to do to check where the problem lies is to #ifdef 0 the original addTo code and just return num +1 in the #else statement to make it easier to predict the expected results, only switch back after you have confirmed the results are as you are expecting

  4. #19
    Registered User
    Join Date
    Jun 2019
    Posts
    44
    First I want to thank all of you. I learn more then I ever known about c and life (sorry for crying out loud). I believe the code I posted caused most or all of my problems. All of that unneeded code reopening, flushing, flipping bits and such could have interfered with cron environment variable(s). It has to be that because I did something correctly at least once out of hundreds of tries! Cron simply refused to run the next command in line. Even my time-slots were perfect at least 70% of the time, even before I started using the crontab.guru tool. Your right laserlight, it’s a must have. It’s going to be interesting to find out what part of my code popped cron in the eye. .. or what I done wrong. I hope it was something I did wrong.

    JFYI, the only thing I became good at with c is file switching and flushing files to reformat documents, now html pages. The functions that laserlight and Salem shared with me few months ago took my little applications over the top. Salem .. you know you done it again. I thought I had a masterpiece until I saw your seven-liner cat-walk the cron at first run, then all day long. On a scale from 1-7 after witnessing all this and studying awsdert breakdown of my code I’ll be at level-4 very soon.

    Thanks again cboard

  5. #20
    Registered User
    Join Date
    Jun 2019
    Posts
    44
    Cron really can run anything. Same as Salem solution - - && ./a.out.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 09-13-2012, 08:57 PM
  2. cron troubles
    By Annonymous in forum Linux Programming
    Replies: 6
    Last Post: 05-09-2012, 03:51 PM
  3. creating cron job
    By nitinmhetre in forum Tech Board
    Replies: 3
    Last Post: 12-29-2006, 10:16 AM
  4. Cron - for all you unix people
    By nickname_changed in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 01-03-2004, 11:52 PM

Tags for this Thread