Created
May 16, 2013 03:52
-
-
Save nmccready/5589265 to your computer and use it in GitHub Desktop.
Showing the possibilities of having a log friendly init.d script. At the same time this script still shows instant output as well if run directly. Overrides default echo and functions success and failure.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
. /etc/init.d/functions | |
successVar="-ne \t\t\t\t\t[ \033[32mOK\033[0m ]\n" | |
failureVar="-ne \t\t\t\t\t[ \033[31mFailed\033[0m ]\n" | |
function success(){ | |
echo $successVar | |
} | |
function failure(){ | |
echo $failureVar | |
} | |
function std_echo(){ | |
/bin/echo $* | |
} | |
function logg_echo(){ | |
/bin/echo `date` : - $* >> ~/init_d.log 2>&1 & | |
} | |
function echo(){ | |
#log & echo at the same time | |
all=$* | |
if [[ "$all" == "$successVar" ]]; then | |
loggOnly="[ Ok ]" | |
elif [[ "$all" == "$failureVar" ]]; then | |
loggOnly="[ Failed ]" | |
else | |
loggOnly="$all" | |
fi | |
std_echo `date` | |
std_echo ${all} | |
logg_echo ${loggOnly} | |
} | |
if [ $1 == 1 ]; then | |
success | |
else | |
failure | |
fi | |
#test normal echos | |
echo Holla back! sweet!!!!!! | |
echo WOWZA! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment