查找问题

5年以前  |  阅读数:471 次  |  编程语言:Shell 
#!/bin/bash
#
# Find_Problem - finds problem records using keywords
#
###########################################################
#
# Determine sql location & set variable
#
MYSQL=`which mysql`" Problem_Trek -u root"
#
##########################################################
#
# Obtain Keyword(s)
#
if [ -n "$1" ]      # Check if a keyword was passed
then                # Grab all the passed keywords
#
    KEYWORDS=$@     # Grab all the params as separate words, same string
#
else                # Keyword(s) not passed, Ask for them
    echo 
    echo "What keywords would you like to search for?"
    echo -e "Please separate words by a space: \c"
    read ANSWER
    KEYWORDS=$ANSWER
fi
#
#######################################################
#
# Find problem record
#
echo
echo "The following was found using keywords: $KEYWORDS"
echo
#
KEYWORDS=`echo $KEYWORDS | sed 's/ /|/g'`
#
$MYSQL <<EOF
SELECT * FROM problem_logger WHERE prob_symptoms REGEXP '($KEYWORDS)' OR prob_solutions REGEXP '($KEYWORDS)'\G
EOF
#

Copyright© 2013-2020

All Rights Reserved 京ICP备2023019179号-8