hbbs

[archived] bbs.hlirc.net
git clone https://hhvn.uk/hbbs
git clone git://hhvn.uk/hbbs
Log | Files | Refs | README | LICENSE

log.sh (792B)


      1 #!/bin/sh
      2 
      3 . $cwd/include/lock.sh
      4 . $cwd/include/hooks.sh
      5 
      6 add_log(){
      7 	run_hooks "$1"
      8 	lock $datadir/log/log
      9 	awk -v "datadir=$datadir" -v "date=$(date +%Y-%d-%m)" -v "time=$(date +%H:%M)" -v "key=$1" -v "value=$2" -F"	" '
     10 		$1 != date {
     11 			print $0 > datadir"/log/"$1".archive"
     12 			# archive old log entries
     13 		}
     14 		$1 == date # only keep logs from today
     15 		END {printf("%s\t%s\t%s\t%s", date, time, key, value)}
     16 		' < $datadir/log/log > $datadir/log/log.new
     17 	mv $datadir/log/log.new $datadir/log/log
     18 	unlock $datadir/log/log
     19 }
     20 
     21 get_log(){
     22 	awk -v "date=$(date +%Y-%d-%m)" -v "key=$1" -F"	" '
     23 		$1 == date && $3 == key {print $4}
     24 		' < $datadir/log/log
     25 }
     26 
     27 get_log_time(){
     28 	awk -v "date=$(date +%Y-%d-%m)" -v "key=$1" -F"	" '
     29 		$1 == date && $3 == key {print $2 "\t" $4}
     30 		' < $datadir/log/log
     31 }