/* Lecture du journal /var/log/adstemps.log qui contient toutes les températures receuillies par le programme ads (mise à jour par copytemp et crontab) Le fichier contient la date en format unix suivit des températures */ #include #include #include #include #include #include #include using namespace std; int main (int argc, char *argv[]) { glocal int ret = -1; glocal const char *journal = "/var/log/adstemps.log"; glocal const char *format = nullptr; glocal.ret = (argc,argv); setproginfo ("templog","0.0","Opérations sur le journal adstemps.log"); setarg ('f',"format","Liste des températures à afficher",glocal.format,false); setarg ('j',"journal","Fichier journal",glocal.journal,false); int ret = -1; if (is_eq(argv[0],"print")){ glocal vector tbf; if (glocal.format != nullptr){ auto tb = str_splitline(glocal.format,','); for (auto s:tb) glocal.tbf.push_back(atoi(s.c_str())+1); // On saute la date dans tb[] } (glocal.journal,true); auto tb = str_splitline(line); if (tb.size() < 2){ tlmp_error ("Ligne invalide: %s\n",line); }else{ time_t date = atoi(tb[0].c_str()); struct tm *t = localtime(&date); printf ("%04d/%02d/%02d %02d:%02d:%02d",t->tm_year+1900,t->tm_mon+1,t->tm_mday,t->tm_hour,t->tm_min,t->tm_sec); if (glocal.tbf.size() > 0){ for (auto n:glocal.tbf){ if (n < tb.size()){ printf (" %6s",tb[n].c_str()); }else{ printf (" "); } } }else{ for (size_t i=1; i } return ret; return glocal.ret; }