Autocreate folder and allow for spaces in base_path

This commit is contained in:
Ceda EI 2018-04-20 14:13:04 +05:30
parent ae6b6ff58d
commit 69b83bb4e0
1 changed files with 5 additions and 4 deletions

9
mark
View File

@ -1,20 +1,21 @@
#!/usr/bin/env bash #!/usr/bin/env bash
source ~/.markrc source ~/.markrc
[[ -d "$base_path" ]] || mkdir -p "$base_path"
today=$(date +%Y-%m-%d\ %H:%M:%S) today=$(date +%Y-%m-%d\ %H:%M:%S)
file_path=$base_path/$(date +%Y-%m).txt file_path="$base_path/$(date +%Y-%m).txt"
login_message="$username $today $login_message" login_message="$username $today $login_message"
logout_message="$username $today $logout_message" logout_message="$username $today $logout_message"
# Login if it is the first message of the day # Login if it is the first message of the day
if [[ -f $file_path ]]; then if [[ -f "$file_path" ]]; then
last_line=$(tail -n1 $file_path) last_line=$(tail -n1 $file_path)
last_day=$(echo $last_line | sed 's/[^ ]* [^-]*-[^-]*-\([^ ]*\).*/\1/') last_day=$(echo $last_line | sed 's/[^ ]* [^-]*-[^-]*-\([^ ]*\).*/\1/')
if [[ $last_day != $(date +%d) ]]; then if [[ $last_day != $(date +%d) ]]; then
echo $login_message >> $file_path echo $login_message >> "$file_path"
fi fi
else else
echo $login_message >> $file_path echo $login_message >> "$file_path"
fi fi
case "$*" in case "$*" in