41 lines
1001 B
Bash
Executable File
41 lines
1001 B
Bash
Executable File
#!/bin/bash
|
|
|
|
|
|
# [1] Launches external script
|
|
####################################################
|
|
# $1 - dependency file
|
|
syscall(){
|
|
# (1) Check file #
|
|
test -z $1 && exit;
|
|
test ! -f $1 && exit;
|
|
|
|
# (2) Call and catch output #
|
|
OUT=$($1);
|
|
|
|
# (3) Clean output : remove leading/ending spaces #
|
|
OUT=$(echo $OUT | tr '\n' '\x' | sed 's/^[ \t\x]*//g' | tr '\x' '\n');
|
|
OUT=$(echo $OUT | tr '\n' '\x' | sed 's/[ \t\x]*$//g' | tr '\x' '\n');
|
|
|
|
# (4) Manage result #
|
|
return $OUT;
|
|
}
|
|
|
|
# [2] Log management
|
|
####################################################
|
|
# $1 - error message
|
|
# $2 - feature
|
|
# $3 - flag
|
|
slog(){
|
|
|
|
test -z "$1" && msg="unknown error" || msg="$1";
|
|
test -z "$2" && feature="main" || feature="$2";
|
|
test -z "$3" && flag="daemon" || flag="$3";
|
|
|
|
test "$msg" = "-" && msg="unknown error" || msg="$1";
|
|
test "$feature" = "-" && feature="main" || feature="$2";
|
|
test "$flag" = "-" && flag="daemon" || flag="$3";
|
|
|
|
echo "$(date +%s) [$feature] $msg" >> $LOG_DIR/$flag.log;
|
|
|
|
}
|