#!/usr/bin/perl # # Original Version # ---------------- # http://www.Linux-1U.net/LCD/scripts/sensor_record.pl # # # Record the various data monitored by lm_sensors # # - called by cron # # # # every day, 5 min after the hour.... record the default set of data # 05 * * * * [path]/sensors_record.pl # # # # every day, Record the temperature every 5 minutes # # # 0,5,10,15,20,25,30,35,40,45,50,55 * * * * sensor_record.pl -data "temp1,temp2,temp3" # # # Usage: # sensor_record.pl [ -data "x,y,z" ] [ -comm "Add this comments" ] # # # 15-May-00 amo Extracted from sensor.pl # 19-May-00 amo Added sensor detected check # 22-May-00 amo Added -c "comments", do $ARGV checking in while loop # 28-May-00 amo Added more comments -- user defined variables # 01-Jun-00 amo Changed date to be 01, 02, 03,... # # # ============================================================================ # ============================================================================ # # Each user needs to modify these 3 variables: # ============================================ # # webgroup - for monitoring via browser # -------- # my ( $WWW ) = "www"; # # # Where to log the data # --------------------- # my ( $LOGS ) = "/home/httpd/html/Monitor.Sensors"; # # # Which data to record # -------------------- # my ( @data ) = ( "fan1", "fan2", "fan3", "temp1", "temp2", "temp3" ); # # # -------------------------------------------- # No other data/variable needs to be changed?? # -------------------------------------------- # # ============================================================================= # ============================================================================= # my ( $NM ) = "sensor_record.pl"; # # # Where is the raw Sensor Data -- Assume raw data exists # my ( $DEV_SENSORS ) = "/proc/sys/dev/sensors/"; # my ( $foox ) = ` cat $DEV_SENSORS/chips`; # 256 w83627hf-isa-0290 my ( $fooy, $CHIP ) = split ( /\s+/, $foox ); # # # my ( $Comment ) = ""; # Add coments to the files # # # Check command line option # ------------------------- # my ( $id ) = 0 ; # while ( $id <= $#ARGV ) { if ( $ARGV[$id] eq "-comm" ) { $id += 1 ; $Comment = $ARGV[$id]; # user defined comments } elsif ( $ARGV[$id] eq "-data" ) { $id += 1 ; @data = split ( /,/, $ARGV[$id] ); # user defined list of variables } $id += 1; # } # check args # # # # ------------------------------------------------------------------------ # # System Defaults # # # from monitor.common.pl # local ( $DATE ) = "/bin/date"; # # my ( $DT ) = `$DATE` ; chomp ( $DT ); my ( $dow, $mon, $dat, $time, $pdt, $year ) = split ( /\s+/, $DT ); # $date = sprintf ( "%02d", $dat ); # # Check that the directory for logging exists # &check_dir ( "$LOGS/${year}_$mon/$date" ); # # # Check if sensors are loaded properly # ---------------------------------------------------------------- # if ( ! -d "$DEV_SENSORS" ) { printf "\n"; printf "ERROR: Missing sensor directory=$DEV_SENSORS\n"; printf "\n"; # # exit 1; # output nothing for now...vs quiting # } # error # # # Record all the user specified data into log files for monitoring # ---------------------------------------------------------------- # my ( $id ) = 0; # while ( $id <= $#data ) { # $d = ` cat $DEV_SENSORS/$CHIP/$data[$id] `; chomp ( $d ); # # printf "Recording $d into $LOGS/${year}_$mon/$data[$id]\n"; # $file = "$LOGS/${year}_$mon/$date/$data[$id]"; # # Insert these comments to the log # if ( $Comment ne "" ) { ` echo "#" >> $file `; ` echo "# $Comment" >> $file `; ` echo "#" >> $file `; } # # Record the data # ` echo "$mon $date $time = $d" >> $file `; # $id += 1; # } # record all the desired data # # exit 0; # # ------------------------------------------------------------------ # # Check if new directory # sub check_dir { my ( $dir ) = @_[0]; # my ( $new ) = 0; my ( $id ) = 0; # # if ( ! -d "$dir" ) { # $new = 1; # printf "\n"; printf "WARNING: Creating new Directory=$dir..\n"; printf "\n"; # ` mkdir -p $dir `; ` chgrp $WWW $dir `; # # # while ( $id <= $#data ) { $log = $data[$id]; # open ( FWR, "> $dir/$log" ); printf FWR "#\n"; printf FWR "# Created by $NM: $DT\n"; printf FWR "#\n"; close ( FWR ); # ` chgrp $WWW "$dir/$log" `; chmod ( 0640, "$dir/$log" ); # $id += 1; # } # all data files # } # new directory # return ( $new ) ; # } # check_dirs # # # end of file