B6: C/C++ Scripts required to start, stop and perform daily cleanup tasks.
program :# include <dirent.h>
# include <stdio.h>
# include <sys/stat.h>
# include<string.h>
# include<fcntl.h>
void quit(char *,int);
void changepdir(char *);
void startServ();
void stopServ();
char path[]="/home/jog/";
struct file1
{
char *filename;
} f[10];
int main()
{
int choice=0,fd;
DIR *dir;
struct dirent *direntry;
printf("\n --------------------------------------------------\n");
printf("\n ** Cleanup service by Onkar Pawar & Prof. V.Jog **\n");
printf("\n ----------------------MENU------------------------\n");
printf("\n \t 1. Start Service");
printf("\n \t 2. Stop Service");
printf("\n \t 3. Exit\nEnter your choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
startServ();
break;
case 2:
stopServ();
break;
case 3:
return 0;
break;
default :
return 0;
}
return 0;
}
void changepdir(char *path)
{
if((chdir(path)==-1)) //goto directory
{
quit("chdir",2);
}
}
void startServ()
{
int fd1,n;
char *line;
fd1=open("/var/spool/cron/root",O_WRONLY);
line="* * * * * /tmp/cleanup/clean_serv.out\n";
n=strlen(line);
write(fd1,line,n);
close(fd1);
printf("\n Cleanup service is started successfully\n");
}
void stopServ()
{
int fd1,n;
/*fchar *min,*hour;*/
char *line;
fopen("/var/spool/cron/root","w");
printf("\n Cleanup service is stopped successfully\n");
}
0 comments:
Post a Comment