linux - How to use init-functions? -


every operating system has librarys. of them gives opportunity more ore write less code. inti-functions 1 of these librarys but...

what init-functions , how use it?

in linux able use init-functions manage deamons , protocol in colored & uniform way. way easier handle recolor every answer.

it stored in /lib/lsb/ under name init-functions.

here have example:

#!/bin/bash # script amir boudani                      ©amir boudani source /lib/lsb/init-functions                  # importing init-functions - log messages                                 # use importing other scripts ore else: "source" / "."                                 # use @ beginning of path "/" path has start root directory  log_success_msg "starting test.sh" || true echo log_action_msg "info message" || true               # info message log_success_msg "checking files" || true            # success message log_warning_msg "free storage under 10%" || true         # warning message log_failure_msg "starting unknown script files" || false    # failure message  echo log_end_msg 0 || true                       # end message - success - resetting line above -> log_daemon_msg log_end_msg 1 || true                       # end message - failure - resetting line above -> log_daemon_msg log_end_msg 255 || true                     # end message - warning - resetting line above -> log_daemon_msg echo log_progress_msg "copying file 2123"                # 1 of line resetting comands - progress echo echo  log_daemon_msg "integrate files" || true sleep 2 log_end_msg 0 || true  log_daemon_msg "checkt if directory 4234 exist" || true sleep 2 log_end_msg 1 || true  log_daemon_msg "storage space checking " || true sleep 2 log_end_msg 255 || true echo echo log_daemon_msg "checking filestorage" || true sleep 1 log_progress_msg "checking file 1"  || true sleep 1 log_progress_msg "checking file 2" || true sleep 1 log_progress_msg "checking file 3"  || true sleep 1 log_progress_msg "checking file 4"  || true sleep 1 log_end_msg 0 || true  echo  #---------------------------------------------------------------# method 1 - not working commands self responding  $checker                            # variable doesn't exist. trigger error code log_daemon_msg "check if last command error" || true if [ "$?" -eq "0" ]                         # "$?" errorcode number of last command. | 0 = there no errors | 1 = error code 1     log_end_msg 0 || true else     log_end_msg 1 || true     echo "       there went wrong. see log" fi  #---------------------------------------------------------------# way check if directory exist  #if [ -d "/opt/scripts"  ]                  # check if directory exist - example @ line: if directory /opt/scripts exist                                 # -d = check if following directory exitst                                 # -a = check if following file exsist #if [ ! -d "/opt/scripts" ]                 # ! negativ operator - example @ line: if directory /opt/scripts not exist                                 # can use ! operator anywhere  #---------------------------------------------------------------# method 2 - working self responding commands. log_daemon_msg ist not working take log_succes/warning/failure_msg  echo echo "type in: false / true / (nothing)" read var1  case $var1 in                           # check if variable var1 true     true)         log_success_msg "check if var1 true" || true         ;;      false)                 log_warning_msg "check if var1 true" || true                 echo -e "       \e[33mvar1 false.\e[0m"                 ;;      *)             log_failure_msg "check if var1 true" || true             echo -e "       \e[31mthere no input in read statment.\e[0m"         ;; esac 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -