problem-record-mysql

 1 #!/bin/bash
 2 #
 3 # Update_Problem - updates problem record in database
 4 ###############################################################
 5 # Determine sql location & set variable
 6 #
 7 MYSQL=`which mysql`" Problem_Task -u testuser"
 8 #
 9 ################################################################
10 #
11 if [ $# -eq 0 ]    #Check if id number was passed.
12 then 
13 #
14 #    Check if any unfinished records exist.
15 #
16 RECORDS_EXIST=`$MYSQL -Bse 'select id_number from problem_logger where
17 fixed_date="0000-00-00" or prob_solutions=""'`
18 #
19 #
20 if [ "$RECORDS_EXIST" != "" ]
21 then
22 echo
23 echo "The following records need updating..."
24 $MYSQL <<EOF
25 select id_number,report_date,prob_symptoms
26 from problem_logger
27 where fixed_date="0000-00-00" or
28 prob_solutions=""G
29 EOF
30 fi
31 echo 
32 echo "What is the ID number for the"
33 echo -e "problem you want to update?:c"
34 read ANSWER
35 ID_NUMBER=$ANSWER
36 else
37 ID_NUMBER=$1
38 fi
39 #
40 ################################################################
41 # Obtain Solution (aka Fixed) Date
42 #
43 echo
44 echo -e "Was problem solved today?[y/n] c"
45 read ANSWER
46 #
47 case ANSWER in 
48 y|Y|yes|Yes|yEs|yeS|YEs|yES|YeS|YES)
49 FIXED_DATE=`date +%Y-%m-%d`
50 ;;
51 *)
52 #if answer is anything but yes,ask for date
53 echo
54 echo -e "What was the date of resolution?[YYYY-MM-DD]c"
55 read ANSWER
56 #
57 FIXED_DATE=$ANSWER
58 ;;
59 esac
60 #
61 ###############################################################
62 # Acquire problem solution
63 #
64 echo
65 echo -e "Briefly describe the problem solution :c"
66 #
67 read ANSWER
68 PROB_SOLUTIONS=$ANSWER
69 #
70 ##############################################################
71 # Update problem record
72 #
73 #
74 echo 
75 echo "Problem record updated as follows:"
76 echo
77 $MYSQL <<EOF
78 UPDATE problem_logger SET
79 prob_solutions="$PROB_SOLUTIONS"
80 fixed_date=$FIXED_DATE
81 WHERE id_number=$ID_NUMBER
82 #
83 select * from problem_logger where id_number=$ID_NUMBERG
84 EOF
85 #
86 #END
原文地址:https://www.cnblogs.com/little-snake/p/4555799.html