2018-04-19 19:21:34 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
source ~/.markrc
|
2018-04-20 10:43:04 +02:00
|
|
|
[[ -d "$base_path" ]] || mkdir -p "$base_path"
|
2018-04-19 19:21:34 +02:00
|
|
|
today=$(date +%Y-%m-%d\ %H:%M:%S)
|
2018-04-20 10:43:04 +02:00
|
|
|
file_path="$base_path/$(date +%Y-%m).txt"
|
2018-04-19 21:16:00 +02:00
|
|
|
login_message="$username $today $login_message"
|
|
|
|
logout_message="$username $today $logout_message"
|
2018-04-19 19:21:34 +02:00
|
|
|
|
|
|
|
# Login if it is the first message of the day
|
2018-04-20 10:43:04 +02:00
|
|
|
if [[ -f "$file_path" ]]; then
|
2018-04-19 19:21:34 +02:00
|
|
|
last_line=$(tail -n1 $file_path)
|
2018-04-19 21:16:00 +02:00
|
|
|
last_day=$(echo $last_line | sed 's/[^ ]* [^-]*-[^-]*-\([^ ]*\).*/\1/')
|
2018-04-19 19:21:34 +02:00
|
|
|
if [[ $last_day != $(date +%d) ]]; then
|
2018-04-20 10:43:04 +02:00
|
|
|
echo $login_message >> "$file_path"
|
2018-04-19 19:21:34 +02:00
|
|
|
fi
|
|
|
|
else
|
2018-04-20 10:43:04 +02:00
|
|
|
echo $login_message >> "$file_path"
|
2018-04-19 19:21:34 +02:00
|
|
|
fi
|
2018-04-19 21:09:58 +02:00
|
|
|
|
|
|
|
case "$*" in
|
|
|
|
"" )
|
|
|
|
echo "Include command"
|
|
|
|
;;
|
|
|
|
login )
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
logout )
|
|
|
|
echo $logout_message >> $file_path
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
* )
|
|
|
|
message=$(echo $* | sed "s/^/$username $today /")
|
|
|
|
echo $message >> $file_path
|
2018-04-19 21:16:00 +02:00
|
|
|
;;
|
|
|
|
esac
|