-
Notifications
You must be signed in to change notification settings - Fork 0
/
script_log-1.1.sh
executable file
·58 lines (48 loc) · 1.56 KB
/
script_log-1.1.sh
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/sh
#####################################################################################################################
#
# script_log-1.1.sh
#
# Author : Spyridakis Christos
# Created Date : 28/2/2019
# Last Updated : 1/4/2019
# Email : spyridakischristos@gmail.com
#
# Description :
# Use this script if you want to run a sequence of commands and then save
# to a log file the date and time of execution
#
# E.G. if you want to update or/and to updgrade your sustem using crontab
# once in a while and you need to have logs for this action you could put
# this script on crontab
#
# Known Bugs:
# You need to use a valid path, this means that FILE_PATH must exists
#
####################################################################################################################
# CHANGE BELOW VARIABLES' VALUES ACCORDING TO YOUR NEEDS
FILE_NAME='ADD_YOUR_LOG_FILE_NAME'
FILE_PATH='~/ABSOLUTE_PATH/TO/THIS/LOG/FILE'
MESSAGE='LOG_MESSAGE_YOU_WANT_TO_PRINT'
FILE_EXTENSION='txt'
# Create paths
FILE="${FILE_PATH}/${FILE_NAME}.${FILE_EXTENSION}"
TMP="${FILE_PATH}/${FILE_NAME}_TEMP.${FILE_EXTENSION}"
####################################
#
# Put commands here
#
####################################
#Create directories that don't exist
if [ ! -d ${FILE_PATH} ] ; then
#TODO : need to use Absolute path
#mkdir -p ${FILE_PATH}
fi
#Create log file or insert log data at the beginning
if [ -e ${FILE} ] ; then
cp ${FILE} ${TMP}
(echo ${MESSAGE} && date -R && echo && cat ${TMP}) > ${FILE}
rm ${TMP}
else
(echo ${MESSAGE} && date -R) > ${FILE}
fi