-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcronJob.c
More file actions
47 lines (42 loc) · 966 Bytes
/
Copy pathcronJob.c
File metadata and controls
47 lines (42 loc) · 966 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<dirent.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<sys/wait.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>
#include<time.h>
#include<sys/types.h>
#include<sys/resource.h>
void execute_cmd();
void vi();
extern void cronJob(char *argv[], int len)
{
char *actual_cmd[100], cmdlen=0;
char *sleep_cmd[100];
int i =2;
while(strcmp(argv[i], "-t")!=0)
{
printf("%s\n", argv[i]);
actual_cmd[cmdlen]= (char *)(malloc(100));
strcpy(actual_cmd[cmdlen], argv[i]);
cmdlen++;
i++;
}
actual_cmd[i-2] = NULL; i++;
sleep_cmd[1] = (char *)(malloc(100));
sleep_cmd[0] = (char *)(malloc(100));
int interval = atoi(argv[i]); strcpy(sleep_cmd[1], argv[i]); i++;
int totalTime = atoi(argv[i+1]);
int timenow = 0;
strcpy(sleep_cmd[0], "sleep");
sleep_cmd[2] = NULL;
while(timenow<totalTime)
{
vi(sleep_cmd, 3);
execute_cmd(actual_cmd, cmdlen);
timenow += interval;
}
printf("CronJob Task Complete\n");
}