Testing if a Daemon is alive or not with Shell -


i have log_sender.pl perl script when executed runs daemon. want make test, using shell:

 #!/bin/bash                                                                                                                                 function log_sender()  {      perl -i $home/script/log_sender.pl  }   (    [[ "${bash_source[0]}" == "${0}" ]] || exit 0    function check_log_sender()       {           if [ "ps -aef | grep -v grep log_sender.pl" ];               echo "passed"               else               echo failed           fi      }        log_sender      check_log_sender   ) 

unfortunately when run terminal becomes:

 -bash-4.1$ sh log_sender.sh   ...     ... 

what doing wrong?

> if [ "ps -aef | grep -v grep log_sender.pl" ]; 

this not want. try this:

if ps -aef | grep -q 'log_sender\.pl';     ... 

in shell script, if construct takes argument command exit status examines. in code, command [ (also known test) , run on literal string "ps -aef | grep -v grep log_sender.pl" true.

you intended check whether ps -aef outputs line contains log_sender.pl not contain grep; ps -aef | grep -v grep | grep 'log_sender\.pl' can avoid grep -v specifying regular expression not match itself.

the -q option grep suppresses output; exit code indicates whether or not input matched regular expression.

the perl invocation not correct; -i option requires argument, saying perl , perl interpreter waiting type in perl script execute. apparently script log_sender.pl should drop -i (or add argument it, if need add perl library paths in order script work).

finally, if write bash script, should execute bash.

chmod +x log_sender.sh ./log_sender.sh 

or alternatively

bash ./log_sender.sh 

the bash_source construct use bashism, script not work correctly under sh.

finally, parentheses around main logic redundant. cause script run these commands in separate subshell no apparent benefit.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -