Results 1 to 4 of 4

Thread: Executing a specific command on event with C or C++

  1. #1
    Junior Member
    Join Date
    Feb 2004
    Location
    Greece
    Posts
    16

    Executing a specific command on event with C or C++

    Hello people,

    I am trying to find a way to create a litle program/script using C
    that its job will be to check a specific ip every eg 5 minutes
    (an endless loop) and if for example one ping will fail to execute an external command and stop.

    Any ideas?

    I already wrote a script tha will send an sms using a http api
    but now I have to think a way how can I run it when a server will fail
    writing a C program...

    Regards,
    Chris
    Everyone gets away with something. No one gets away with everything...

  2. #2
    Senior Member
    Join Date
    Mar 2004
    Posts
    557
    Hi

    Have a look at the IcmpSendEcho function[1] for the ping,
    and a look at system()-command to execute external programs.


    Good luck



    [1] http://msdn2.microsoft.com/en-us/library/Aa366050.aspx
    If the only tool you have is a hammer, you tend to see every problem as a nail.
    (Abraham Maslow, Psychologist, 1908-70)

  3. #3
    Senior Member
    Join Date
    Oct 2005
    Posts
    106
    I may be a little overzealous with daemons here, but shouldn't a daemon be capable of doing this job? If you're not using a *nix machine, I would have no clue how you would go about it though...

    The system() function is a good one, far better than the exec() alternatives in my opinion.

    But it seems a priori that having an endless while() loop would be inefficient. It'd be like asking repeatedly "Is it time yet? How about now? Now? now?!" Disclaimer: you could have very well written something like:

    Code:
    while(true) {
         do_check(); //checks for whatever you're looking for
         sleep(5*60*1000); // sleeps for 5 * 60 seconds, or 5 minutes
    }
    This is a good solution because it spares CPU cycles. The alternative that I assume you have is something like:

    Code:
     unsigned int time = current_time();
    while(true) {
         if(current_time() - time == /* 5 minutes */) {
              do_check(); //whatever you're checking
              time = current_time(); // change the time variable
         }
    }
    This is worse because there are more CPU cycles dedicated to checking the difference in time. That's inefficient.

    I myself am inclined to use recursion, but I'm just a whacky coder like that.

    Just my two cents...
    "The Texan turned out to be good-natured, generous and likeable. In three days no one could stand him." Catch 22 by Joseph Heller.

    Buddies? I have no buddies...


    Give the BSD daemon some love (proud FreeBSD user)

  4. #4
    Custom User
    Join Date
    Oct 2001
    Posts
    503
    What about writing a program that only sends the ping once then getting the scheduler to execute it every 5 mins?

    ac

Similar Threads

  1. Windows Error Messages
    By cheyenne1212 in forum Miscellaneous Security Discussions
    Replies: 7
    Last Post: February 1st, 2012, 02:51 PM
  2. Replies: 1
    Last Post: December 1st, 2005, 12:24 AM
  3. Event Logs the easy way
    By Tedob1 in forum The Security Tutorials Forum
    Replies: 2
    Last Post: April 2nd, 2004, 04:27 PM
  4. Tcp/ip
    By gore in forum Newbie Security Questions
    Replies: 11
    Last Post: December 29th, 2003, 08:01 AM
  5. Someone PLEASE HELP: (router;NIC;DHCP;IP)<-HELP
    By PhiDelt101 in forum General Computer Discussions
    Replies: 7
    Last Post: December 12th, 2003, 04:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •