Skip to content

Instantly share code, notes, and snippets.

@nmccready
Created May 16, 2013 03:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmccready/5589265 to your computer and use it in GitHub Desktop.
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.
#!/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