sched.c

pdirt/drv/utils/sched.c · 1.0 KB

From the archive pDirt-1_tar.gz

Download the archive   « Back to the archive contents

#include <stdio.h>
#include <unistd.h>
#include <time.h>

void main(int argc, char *argv[])
{  time_t curr;
   struct tm t,*now;
   int ret;
   char *p,buffer[80];

    curr = time(0);
    now = gmtime(&curr);
    if (argc < 2 )
    {  printf("Usage: sched <time> <task>\n");
       exit(1);
    }

    ret = sscanf(argv[1],"%d:%d",&t.tm_hour,&t.tm_min);

    printf("Will do %s on %d:%d\n",argv[2],t.tm_hour,t.tm_min);

    while (now->tm_hour != t.tm_hour && now->tm_min != t.tm_min)
    {  sleep(40);
       curr = time(0);
       now = gmtime(&curr);
    }
    if (argc > 2)
      p = argv[3];
    else
      p = NULL;
    /* Lets do some work */
/*
    if (execlp((const char *)argv[2],(const char *)p)== -1);
       printf("Not able to change image\n");
 */
    strcpy(buffer,argv[2]);
    strcat(buffer," &");
    ret = system((const char *)argv[2]);
    if (ret == 127)
    { printf("Couldn't find shell\n");
      exit(1);
    } else if (ret == -1)
    { printf("error executing file\n");
      exit(1);
    } else
    exit(0);
}

Site Stats

Snippets: 1791
Codebases: 571