-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.sh
81 lines (67 loc) · 1.61 KB
/
common.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
function commandlog {
if [[ $2 == "test" ]]; then
log "[Execut'n (TEST)] $1"
return
fi
log "[Execut'n] $1"
startTime=`date +%s`
eval "$1" | blogger --logFile "$logPath/$scriptName.log" -t "[DEBUG] $scriptName [$1]"
endTime=`date +%s`
let elapsedTime=$endTime-$startTime
debug "[Executed (in $elapsedTime seconds)] $1"
}
function sucommandlog {
log "[Sudoing!] $1"
commandlog "su $1"
# startTime=`date +%s`
# eval "$1" | blogger --logFile "$logPath/$scriptName.log" -t "[DEBUG] $scriptName [$1]"
# endTime=`date +%s`
# let elapsedTime=$endTime-$startTime
# debug "[Executed (in $elapsedTime seconds)] $1"
}
function log {
if [[ $scriptName = "" ]]
then
scriptName="Script"
fi
if [[ $logPath = "" ]]
then
logPath="/var/log/Scripts/"
fi
generatedLogLine="$scriptName: $1"
echo "$generatedLogLine" | blogger --logFile "$logPath/$scriptName.log"
if [[ $SHELLOPTS = *"interactive"* ]]; then
echo "$generatedLogLine"
# debug "Interactive shell detected"
fi
}
function instanceme {
if [[ $lockFile == "" ]]; then
debug "lock file not defined, setting default lockFile"
lockFile="$scriptName.lock"
fi
if [ -f "/tmp/$lockFile" ]; then
log "Another instance running, exiting..."
exit
else
log "Instance initiated"
touch "/tmp/$lockFile"
fi
}
function deinstanceme {
rm "/tmp/$lockFile"
}
function warning {
log "[Warn] $1"
}
function debug {
log "[DEBUG] $1"
}
function error {
log "[ERROR] $1"
logger -t "$scriptName" "[ERROR] $1"
}
function testReturn () {
return "calimocho"
}