Advertisement
mbah_bejo

cadangan1

Apr 23rd, 2021
855
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.29 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <sys/types.h>
  3. #include <unistd.h>
  4. #include <time.h>
  5. #include <wait.h>
  6. #include <string.h>
  7. #include <stdio.h>
  8. #include <ctype.h>
  9. #include <fcntl.h>
  10. #include <errno.h>
  11. #include <unistd.h>
  12. #include <sys/stat.h>
  13. #include <syslog.h>
  14. #include <glob.h>
  15.  
  16. char path[20];
  17. short flag=0;
  18.  
  19. void filter_prosess(char* sumber, char* tujuan)
  20. {
  21.     pid_t child_id;
  22.     int status;
  23.  
  24.     child_id = fork();
  25.  
  26.     if (child_id < 0)
  27.         exit(EXIT_FAILURE);
  28.  
  29.     if (child_id == 0)
  30.     {
  31.     glob_t globbuf_film;
  32.     globbuf_film.gl_offs = 2;
  33.     glob(sumber, GLOB_DOOFFS, NULL, &globbuf_film);
  34.     glob(tujuan, GLOB_DOOFFS | GLOB_APPEND, NULL, &globbuf_film);
  35.     globbuf_film.gl_pathv[0] = "cp";
  36.     globbuf_film.gl_pathv[1] = "-r";
  37.     execvp("cp", &globbuf_film.gl_pathv[0]);
  38.     // exit(1);
  39.     }
  40. }
  41.  
  42. void hbd(){
  43.   int status,status2;
  44.   time_t t_now = time(NULL);
  45.   struct tm waktu = *localtime(&t_now);
  46.  
  47. while(wait(&status2)>0);
  48.  
  49.   while(strcmp(path,"09-04_22:22") !=0){
  50.     sleep(2);
  51.     t_now = time(NULL);
  52.     waktu = *localtime(&t_now);
  53.     strftime(path, sizeof(path)-1, "%d-%m_%H:%M", &waktu);
  54.     }
  55.  
  56.   pid_t child_id;
  57.   child_id = fork();
  58.  
  59.   // if (child_id < 0) {
  60.   //   exit(EXIT_FAILURE); // Jika gagal membuat proses baru, program akan berhenti
  61.   // }
  62.  
  63.   if (child_id == 0) {
  64.     char *argv_6[] = {"rm","-rf", "MUSIK", "FOTO", "FILM", NULL};
  65.     execv("/bin/rm", argv_6);
  66.   } else{
  67.     while(wait(&status)>0);
  68.     char *argv_4[] = {"zip", "-rm", "Lopyu_Stevany", ".", "-x", "soal1*", "*.zip", NULL};
  69.     execv("/bin/zip", argv_4);
  70.     flag=0;
  71.   }
  72. }
  73.  
  74. void wget_img(char* link, char* name)
  75. {
  76.     pid_t child_id;
  77.     int status;
  78.  
  79.     child_id = fork();
  80.  
  81.     if (child_id < 0)
  82.         exit(EXIT_FAILURE);
  83.  
  84.     if (child_id == 0)
  85.     {
  86.       char *argv[] = {"wget", link, "-q", "-O", name, NULL};
  87.       execv("/usr/bin/wget", argv);
  88.       // exit(1);
  89.     }
  90. }
  91.  
  92. void unzip()
  93. {
  94.     pid_t child_id;
  95.     int status;
  96.  
  97.     child_id = fork();
  98.  
  99.     if (child_id < 0)
  100.         exit(EXIT_FAILURE);
  101.  
  102.     if (child_id == 0)
  103.     {
  104.       char *argv_3[] = {"unzip", "*.zip", NULL};
  105.       execv("/usr/bin/unzip", argv_3);
  106.       // exit(1);
  107.     }
  108. }
  109.  
  110. void folder()
  111. {
  112.     pid_t child_id;
  113.     int status;
  114.  
  115.     child_id = fork();
  116.  
  117.     if (child_id < 0)
  118.         exit(EXIT_FAILURE);
  119.  
  120.     if (child_id == 0)
  121.     {
  122.       char *argv_1[] = {"mkdir", "-p", "Musyik", "Fylm", "Pyoto", NULL};
  123.       execv("/bin/mkdir", argv_1);
  124.     }
  125. }
  126.  
  127. void download(){  
  128.   // pid_t child_id;
  129.   int i,j,status,status1,status2,status3,status4,status5,status6;
  130.   // child_id = fork();
  131.  
  132.   // if (child_id < 0) {
  133.   //   exit(EXIT_FAILURE); // Jika gagal membuat proses baru, program akan berhenti
  134.   // }
  135.  
  136.   // if (child_id == 0) {
  137.   //   // this is child
  138.     char *argv[3][2] = {    
  139.     {"https://drive.google.com/uc?id=1ZG8nRBRPquhYXq_sISdsVcXx5VdEgi-J&export=download", "Musik_for_Stevany.zip"},
  140.     {"https://drive.google.com/uc?id=1FsrAzb9B5ixooGUs0dGiBr-rC7TS9wTD&export=download", "Foto_for_Stevany.zip"},
  141.     {"https://drive.google.com/uc?id=1ktjGgDkL0nNpY-vT7rT7O6ZI47Ke9xcp&export=download", "Film_for_Stevany.zip"}};
  142.     for(i = 0; i< 3;i++ ){
  143.       wget_img(argv[i][0], argv[i][1]);
  144.       }
  145.     // }
  146.   //  else{
  147.     // this is parent
  148.    
  149.     while ((wait(&status2)) > 0);
  150.     sleep(3);
  151.   //   pid_t child_id1;
  152.   //   child_id1 = fork();
  153.    
  154.   // if (child_id1 < 0) {
  155.   //   exit(EXIT_FAILURE); // Jika gagal membuat proses baru, program akan berhenti
  156.   // }
  157.  
  158.   // if (child_id1 == 0) {
  159.     unzip();
  160.   // }else{
  161.     while ((wait(&status3)) > 0);
  162.     // id_t child_id2;
  163.     // child_id2 = fork();
  164.  
  165.   // if (child_id2 < 0) {
  166.     // exit(EXIT_FAILURE);
  167.   // }  
  168.  
  169.   // if(child_id2==0){
  170.     // while ((wait(&status)) > 0);
  171.     // while ((wait(&status4)) > 0);
  172.     folder();
  173.    
  174.   // }else{
  175.       while ((wait(&status5)) > 0);
  176.       // id_t child_id3;
  177.       // child_id3 = fork();
  178.  
  179.       // if (child_id3 < 0) {
  180.       // exit(EXIT_FAILURE);
  181.       // }  
  182.  
  183.       // if(child_id3==0){
  184.       char *argv_filter[3][2] = {    
  185.       {"FILM/*.mp4", "Fylm/"},
  186.       {"FOTO/*.jpg", "Pyoto/"},
  187.       {"MUSIK/*.mp3", "Musyik/"}};
  188.       for(i = 0; i< 3;i++ ){
  189.       filter_prosess(argv_filter[i][0], argv_filter[i][1]);
  190.       }
  191.      
  192.       // }else{
  193.          while ((wait(&status6)) > 0);
  194.         hbd();
  195.         // return;
  196.       }
  197. //     }    
  198. //     }
  199. // }
  200. // }
  201. int main() {
  202.   pid_t pid, sid;
  203.   pid = fork();
  204.   if (pid < 0) {
  205.     exit(EXIT_FAILURE);
  206.   }
  207.   if (pid > 0) {
  208.     exit(EXIT_SUCCESS);
  209.   }
  210.   umask(0);
  211.   sid = setsid();
  212.   if (sid < 0) {
  213.     exit(EXIT_FAILURE);
  214.   }
  215.   close(STDIN_FILENO);
  216.   close(STDOUT_FILENO);
  217.   close(STDERR_FILENO);
  218.  
  219.   time_t my_time;
  220.   struct tm *timeinfo;
  221.   while(1){
  222.   time (&my_time);
  223.   timeinfo = localtime (&my_time);
  224.   if(timeinfo->tm_mday == 9 && timeinfo->tm_mon+1 == 4 && timeinfo->tm_hour == 16
  225.   && timeinfo->tm_min == 21 && timeinfo->tm_sec == 59){
  226.     //  pid_t child_id;
  227.     //     child_id = fork();
  228.  
  229.     //     if (child_id < 0)
  230.     //     {
  231.     //         exit(EXIT_FAILURE); // Jika gagal membuat proses baru, program akan berhenti
  232.     //     }
  233.  
  234.     //     if (child_id == 0)
  235.     //     {
  236.             download();
  237.         // }
  238.         sleep(3);
  239.   }
  240.   }
  241. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement