#include #include #include #include #include #include #include #include int state = 0; struct stat a; struct stat b; char *pathServer; void *funcChecker(void *pathClient) { printf("Checker\n"); printf("pathChck: %s\n\n", pathClient); while (1) { stat(pathClient, &a); sleep(1); stat(pathClient, &b); if (a.st_mtime != b.st_mtime) { state = 1; } } } void *funcPrintTimeAndChanges(void *pathClient, void *pathServer) { char command1[256], command2[256], command3[256]; printf("TimeAndChanges\n"); printf("pathClient: %s\n", pathClient); printf("pathServer: %s/pathLog.log\n\n", pathServer); while (1) { if (state == 1) { sprintf(command1, "touch %s/logAll.log &&\ date >>%s/logAll.log && \ echo '%s' >>%s/logAll.log && \ ls -sr %s>>%s/logAll.log &&\ echo '' >>%s/logAll.log", pathServer, pathServer, pathClient, pathServer, pathClient, pathServer, pathServer); system(command1); sprintf(command2, " echo Version%d.0 &&\ echo '\n----------------------------------\n' && \ echo 'Last modified time:' && date -u && \ cat %s/*.txt &&\ echo 'lines: ' && wc -l %s/*.txt &&\ echo 'words: ' && wc -w %s/*.txt &&\ echo 'characters: ' && wc -m %s/*.txt &&\ echo '----------------------------------------\n'", i, pathClient, pathClient, pathClient, pathClient); system(command2); sprintf(command3, "touch %s/%d.txt &&\ cp -r %s/*.txt %s/%d.txt", pathServer, i, pathClient, pathServer, i); system(command3); i++; state = 0; } fflush(stdout); sleep(1); } } int main(int argc, char *argv[]) { if (argc < 3) { printf("%s must be executed with exactly two addtional arguments(pathServer,pathClient)!\n", argv[0]); printf("Typed count is %d \n", argc); printf("Aborted automatically...\n"); exit(0); } if (argc > 3) { printf("Too many arguments! %s must be executed with exactly two addtional arguments(pathRep,pathSub)!\n", argv[0]); printf("Aborted automatically...\n"); exit(0); } if (argc == 3) { if (isdigit(argv[1][0]) || isdigit(argv[2][0])) { printf("Wrong argument! Folder path or paths is not exist!\n"); printf("Aborted automatically...\n"); exit(0); } } printf("Main\n"); printf("pathServer: %s\n", argv[1]); printf("pathClient: %s\n\n", argv[2]); pthread_t threadChecker; pthread_t threadWorker; pthread_create(&threadChecker, NULL, funcChecker, argv[2]); pthread_create(&threadWorker, NULL, funcPrintTimeAndChanges, argv[2]); pthread_join(threadChecker, NULL); pthread_join(threadWorker, NULL); }