Quote:
Originally Posted by zee#
What else can I use instead of -z to check for any 5 digit number?
|
Nope. The process ID could be a 4-digit number as well. Indeed, the syntax of the original code is correct and the cause of the problem has to be searched somewhere else.
Looking at the sphynx documentation:
Quote:
searchd is not designed to be run either from a regular script or command-line calling, but instead either as a daemon to be called from init.d
|
this means that launching searchd as a command could not be the right way. Moreover it should require root privileges to act as a daemon.
More important, you should investigate why searchd stops if it is not supposed to do. If it crashes, it could even leave a lock behind, that prevent the system from running further sessions.
An aside note related to the code posted in the OP: you don't really need to grep for digits, since the
if <command> syntax checks the exit status of the command and acts accordingly. Since pgrep returns 0 when find matches and 1 otherwise, this is enough. Moreover, you can reverse the expression using negation (an exclamation mark) so that you can avoid the "do-nothing" command:
Code:
if ! pgrep searchd > /dev/null
then
<do something to restart the search daemon>
fi
Note the redirection of the output from pgrep to /dev/null. This is to avoid an unnecessary standard output that would be sent to you by mail from the cron daemon (if not redirected).