Update_Problem

3年以前  |  阅读数:159 次  |  编程语言: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
将二进制数据转为16进制以便显示
获取IMSI
获取IMEI
Java生成UUID
PHP自定义函数获取搜索引擎来源关键字的方法
让你成为最历害的git提交人
在Zeus Web Server中安装PHP语言支持
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php+ajax+json 详解及实例代码
Yii2汉字转拼音类的实例代码
php封装的page分页类完整实例
php数组合并array_merge()函数使用注意事项
PHP设计模式之工厂模式与单例模式
PHP实现简单爬虫的方法
php实现数组中索引关联数据转换成json对象的方法
wget使用技巧