Update_Problem

4年以前  |  阅读数:278 次  |  编程语言:Shell 
#!/bin/bash
#
# Update_Problem - updates problem record in database
#
############################################################
#
# Determine sql location & set variable
#
MYSQL=`which mysql`" Problem_Trek -u root"
#
##############################################################
#
# Obtain Record Id
#
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
        SELECT id_number, report_date, prob_symptoms FROM problem_logger WHERE fixed_date="0000-00-00" OR prob_solutions=""\G
EOF
    fi
#
    echo
    echo "What is the ID number for the"
    echo -e "problem you want to update?: \c"
    read ANSWER
    ID_NUMBER=$ANSWER
else
    ID_NUMBER=$1
fi
#
##########################################################
#
# Obtain Solution (aka Fixed) Date
#
echo
echo -e "Was Problem solved today? (y/n) \c"
read ANSWER
#
case $ANSWER in
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
;;
esac
#
########################################################
#
# Acquire problem solution
#
echo
echo -e "Birefly describe the problem solution: \c"
#
read ANSWER
PROB_SOLUTIONS=$ANSWER
#
########################################################
# 
# Update problem record
#
echo
echo "Problem record updated as follows:"
echo
$MYSQL <<EOF
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
 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例