-
Notifications
You must be signed in to change notification settings - Fork 0
/
bash_logging.script
36 lines (31 loc) · 1.36 KB
/
bash_logging.script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#####################################################################################################
# DESCRIPTION: This is just a very simple logging function
# because I'm lazy and want to have a repeatable
# and nice looking log output. It took me a solid
# 20 minutes to figure out exactly what i wanted so here. :)
#####################################################################################################
LOGDIR=/tmp/cce_audit_logs/ #CHANGE THIS
if [[ -d $LOGDIR ]]; then
echo "$LOGDIR found, continuing..."
else
mkdir -p $LOGDIR
echo "$LOGDIR created, continuing..."
fi
function loggy(){
while read data; do
TIMESTAMP=$(date '+%d/%m/%Y %H:%M:%S')
LOG="$LOGDIRlog.log" #CHANGE THIS
echo "$(hostname):$TIMESTAMP -> $data" | tee $LOG
done
}
### EXAMPLE ###
echo "Starting Script v1.0" | loggy
echo "Script ran out of gas" | loggy
ping www.google.com | loggy
### OUTPUT ###
hacbook:08/10/2020 21:47:31 -> Beginning Log Function Test
hacbook:08/10/2020 21:51:10 -> Starting Script v1.0
hacbook:08/10/2020 21:51:10 -> Script ran out of gas
hacbook:08/10/2020 21:51:10 -> PING www.google.com (172.217.1.36): 56 data bytes
hacbook:08/10/2020 21:51:10 -> 64 bytes from 172.217.1.36: icmp_seq=0 ttl=116 time=32.801 ms
hacbook:08/10/2020 21:51:11 -> 64 bytes from 172.217.1.36: icmp_seq=1 ttl=116 time=40.646 ms