This commit is contained in:
colben 2022-04-12 08:03:17 +08:00
parent a7aec4c003
commit 0de0b3cd2b

View File

@ -3,8 +3,9 @@
cat <<-EOF cat <<-EOF
#!/bin/bash #!/bin/bash
#========================================= #=========================================
# Author : Colben # Company : Boyachain
# Create : $(date +"%F %R") # Create : $(date +"%F %R")
# Author : Who the f**k r u!
#========================================= #=========================================
set -euo pipefail set -euo pipefail
@ -14,14 +15,14 @@ trap Quit EXIT
PID_FILE=/tmp/\$(basename \${0%.sh}).pid PID_FILE=/tmp/\$(basename \${0%.sh}).pid
if [ -t 0 ]; then if [ -t 0 ]; then
function Print { echo -e "\033[32;1m\$(date +'[%F %T]') \$*\033[0m"; } function Print { echo -e "\033[36;1m\$(date +'[%F %T]')\033[32;1m \$*\033[0m"; }
function Warn { echo -e "\033[33;1m\$(date +'[%F %T]') \$*\033[0m"; } function Warn { echo -e "\033[36;1m\$(date +'[%F %T]')\033[33;1m \$*\033[0m"; }
function Error { echo -e "\033[31;1m\$(date +'[%F %T]') \$*\033[0m"; exit 1; } function Error { echo -e "\033[36;1m\$(date +'[%F %T]')\033[31;1m \$*\033[0m"; exit 1; }
else else
#exec &> \${0%.sh}.out #exec &> \${0%.sh}.out
function Print { echo -e "\$(date +'[%F %T] INFO') \$*"; } function Print { echo -e "\$(date +'[%F %T INFO]') \$*"; }
function Warn { echo -e "\$(date +'[%F %T] WARN') \$*"; } function Warn { echo -e "\$(date +'[%F %T WARN]') \$*"; }
function Error { echo -e "\$(date +'[%F %T] ERRRO') \$*"; exit 1; } function Error { echo -e "\$(date +'[%F %T ERROR]') \$*"; exit 1; }
fi fi
function Quit { function Quit {
@ -33,17 +34,17 @@ function Quit {
} }
function Func1 { function Func1 {
Print Func1 ... Warn Func1 ...
} }
function Func2 { function Func2 {
Print Func2 ... Warn Func2 ...
} }
function Main { function Main {
[ -e "\$PID_FILE" ] && Error Pid file \$PID_FILE already exists, quit! [ -e "\$PID_FILE" ] && Error Pid file \$PID_FILE already exists, quit!
echo \$\$ > \$PID_FILE echo \$\$ > \$PID_FILE
Print Main ... Warn Main ...
Func1 Func1
Func2 Func2
END=1 END=1