linux-tutorial/codes/shell/示例脚本/进阶脚本/问题跟踪数据库/Update_Problem.sh

85 lines
1.9 KiB
Bash
Raw Normal View History

2019-05-10 11:17:57 +08:00
#!/bin/bash
2019-10-10 08:56:31 +08:00
2019-05-10 11:17:57 +08:00
#
# Update_Problem - updates problem record in database
#
############################################################
#
# Determine sql location & set variable
#
MYSQL=`which mysql`" Problem_Trek -u root"
#
##############################################################
#
# Obtain Record Id
#
2019-10-10 08:56:31 +08:00
if [ $# -eq 0 ] # Check if id number was passed
then
# If not passed ask for it
#
# Check if any unfinished records exist.
RECORDS_EXIST=`$MYSQL -Bse 'SELECT id_number FROM problem_logger where fixed_date="0000-00-00" OR prob_solutions=""'`
#
if [ "$RECORDS_EXIST" != "" ]
then
echo
echo "The following record(s) need updating..."
$MYSQL << EOF
2019-05-10 11:17:57 +08:00
SELECT id_number, report_date, prob_symptoms FROM problem_logger WHERE fixed_date="0000-00-00" OR prob_solutions=""\G
EOF
2019-10-10 08:56:31 +08:00
fi
#
echo
echo "What is the ID number for the"
echo -e "problem you want to update?: \c"
read ANSWER
ID_NUMBER=$ANSWER
2019-05-10 11:17:57 +08:00
else
2019-10-10 08:56:31 +08:00
ID_NUMBER=$1
2019-05-10 11:17:57 +08:00
fi
#
##########################################################
#
# Obtain Solution (aka Fixed) Date
#
echo
echo -e "Was Problem solved today? (y/n) \c"
read ANSWER
#
case $ANSWER in
2019-10-10 08:56:31 +08:00
y | Y | YES | yes | Yes | yEs | yeS | YEs | yES)
#
FIXED_DATE=`date +%Y%m%d`
;;
*)
# if answer is anything but "yes", ask for date
echo
echo -e "What was the date of resolution? [YYYYMMDD] \c"
read ANSWER
#
FIXED_DATE=$ANSWER
;;
2019-05-10 11:17:57 +08:00
esac
#
########################################################
#
# Acquire problem solution
#
echo
echo -e "Birefly describe the problem solution: \c"
#
read ANSWER
PROB_SOLUTIONS=$ANSWER
#
########################################################
2019-10-10 08:56:31 +08:00
#
2019-05-10 11:17:57 +08:00
# Update problem record
#
echo
echo "Problem record updated as follows:"
echo
2019-10-10 08:56:31 +08:00
$MYSQL << EOF
2019-05-10 11:17:57 +08:00
UPDATE problem_logger SET prob_solutions="$PROB_SOLUTIONS", fixed_date=$FIXED_DATE where id_number=$ID_NUMBER;
SELECT * FROM problem_logger WHERE id_number=$ID_NUMBER\G
EOF