#include #include #include #include #define INFILE "/u/hans/watersys/wsys.ftp_last" main(int argc, char **argv) { time_t t0, t1; struct tm tt0, tt1; FILE *in; char wday_str[20], mon_str[20], jst_str[20], str[256]; int year, mon, day, hour, min, sec, diff_sec, dflag; if ((in=fopen(INFILE,"rb"))!=NULL) { if (!ferror(in) && !feof(in) && fgets(str,256,in)) { if (9==sscanf(str,"%s %s %d %d:%d:%d %s %d %d", wday_str, mon_str, &day, \ &hour, &min, &sec, jst_str, &year, &dflag)) { fclose(in); if (strstr(mon_str,"Jan")) mon=0; if (strstr(mon_str,"Feb")) mon=1; if (strstr(mon_str,"Mar")) mon=2; if (strstr(mon_str,"Apr")) mon=3; if (strstr(mon_str,"May")) mon=4; if (strstr(mon_str,"Jun")) mon=5; if (strstr(mon_str,"Jul")) mon=6; if (strstr(mon_str,"Aug")) mon=7; if (strstr(mon_str,"Sep")) mon=8; if (strstr(mon_str,"Oct")) mon=9; if (strstr(mon_str,"Nov")) mon=10; if (strstr(mon_str,"Dec")) mon=11; tt0.tm_year = year - 1900; tt0.tm_mon = mon; tt0.tm_mday = day; tt0.tm_hour = hour; tt0.tm_min = min; tt0.tm_sec = sec; tt0.tm_isdst = 0; t0 = mktime(&tt0); t1 = time(NULL); tt1 = *localtime(&t1); diff_sec = (int) t1 - (int) t0; /* set alarm if last successful ftp was more than 3 hours ago and second alarm if more than 6,12,18,... hours ago and still not fixed. */ if ( ( (dflag == 0) && (diff_sec > (3*3600)) ) || \ ( (dflag == 1) && (diff_sec > (6*3600)) ) || \ ( (dflag == 2) && (diff_sec > (12*3600)) ) || \ ( (dflag == 3) && (diff_sec > (24*3600)) ) || \ ( (dflag == 4) && (diff_sec > (36*3600)) ) ) { dflag++; if ((in=fopen(INFILE,"w"))!=NULL) { fprintf(in,"%s %s %2d %02d:%02d:%02d %s %4d %d\n", \ wday_str, mon_str, day, hour, min, sec, jst_str, year, dflag); fclose(in); } printf("This is an automated message generated by a script.\n\nAlert!!\n"); printf("The ftp connection to the K2K watersystem PC is malfunctioning!\n"); printf("Please check one or more of the possibilities:\n"); printf(" - Network problem at KEK or between KEK and UCI?\n"); printf(" - Was/is there a power outage?\n"); // printf(" - Is the PC (fdwat2) down and needs to be rebooted?\n"); printf(" - Is the PC at UCI down and needs to be rebooted?\n"); printf(" - Is 'QVT/Net FTP server' (ftpd) on the UCI PC frozen?\n"); printf("Last succesful ftp access was %3.1f hours ago at\n", ((float) diff_sec)/3600); printf("%s %s %2d %02d:%02d:%02d %s %4d\n\n Best Regards.\n - your friendly plot robot\n\n", \ wday_str, mon_str, day, hour, min, sec, jst_str, year); printf("URL: http://neutrino.kek.jp/shift/monitor/watersys/\n"); } else { printf("warning already sent...\n"); } } } } }