Skip to content

Commit

Permalink
Added a more robust dateString function.
Browse files Browse the repository at this point in the history
  • Loading branch information
Node0 authored Apr 26, 2022
1 parent 984b185 commit 1ed8a70
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions BASH/activityLog/activityLog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -202,27 +202,32 @@ if (( finiteHistory == 1 )); then
done;
fi

#Grab a timeslice of system activity
# Modular dateString generation (can be injected into any cron invoked script)
function dateString {
dsDate=$(which \date);
dsSed=$(which \sed);
dsCut=$(which \cut);
dsMd5sum=$(which \md5sum);
dsHead=$(which \head);
if [[ $1 == "" ]]; then
dateStrng=$(command date +'%a %m-%d-%Y at %k%Mh %Ss' |command sed -r "s~(\s)~_~g" |command sed -r "s~(__)~_~g" );
dateStrng=$( ${dsDate} +'%a %m-%d-%Y at %k%Mh %Ss' | ${dsSed} -r "s~(\s)~_~g" | ${dsSed} -r "s~(__)~_~g" );
echo "${dateStrng}";
fi
if [[ $1 == "ss" ]]; then
dateStrng=$(command date +%s%N | cut -b1-13);
dateStrng=$( ${dsDate} +%s%N | ${dsCut} -b1-13);
echo "${dateStrng}";
fi
if [[ $1 == "ms" ]]; then
dateStrng=$(command date +%s%N | cut -b1-13);
dateStrng=$( ${dsDate} +%s%N | ${dsCut} -b1-13);
echo "${dateStrng}";
fi
if [[ $1 == "epoch" ]]; then
dateStrng=$(command date +'%s' );
dateStrng=$( ${dsDate} +'%s' );
echo "${dateStrng}";
fi
if [[ $1 == "hcode" ]]; then
dateStrng=$(command date +'%a %m-%d-%Y at %k%Mh %Ss' |command sed -r "s~(\s)~_~g" |command sed -r "s~(__)~_~g" );
hashCode=$(command date +'%N' |md5sum |cut -b 1,3,5,7,9);
dateStrng=$( ${dsDate} +'%a %m-%d-%Y at %k%Mh %Ss' | ${dsSed} -r "s~(\s)~_~g" | ${dsSed} -r "s~(__)~_~g" );
hashCode=$( ${dsHead} -n 1 /dev/random | ${dsMd5sum} | ${dsCut} -b 1,3,5,7,9);
echo ""${dateStrng}"-"${hashCode}"";
fi
}
Expand Down

0 comments on commit 1ed8a70

Please sign in to comment.