-
Notifications
You must be signed in to change notification settings - Fork 1
/
mysql_version.sh
40 lines (31 loc) · 890 Bytes
/
mysql_version.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# -----------------------------------------------------------------------------
# Name : mysql_version.sh
# Description : get mysql version
# Author : qiaolei
# Date : 2014/10/13
# -----------------------------------------------------------------------------
#!/bin/sh
usage()
{
echo "Usage: $0 <username> <password>"
}
if [ $# -ne 2 ]
then
usage
exit 1
fi
LOG_FILE=/tmp/mysql_scripts.log
if [ ! -f $LOG_FILE ];then
touch $LOG_FILE
fi
TIMESTAMP=`date +%Y%m%d%H%M%S`
echo "@$TIMESTAMP: {$0 $*}" >$LOG_FILE
USERNAME=$1
PASSWORD=$2
if [ ! $PASSWORD = "NULL" ];then
VERSION=`mysqladmin -u${USERNAME} -p${PASSWORD} version | grep "Server version" | awk '{print $3}'`
else
VERSION=`mysqladmin -u${USERNAME} version | grep "Server version" | awk '{print $3}'`
fi
RESULT=`printf "%s%s%s%s" "$RESULT" "{\"version\": " "\"$VERSION\"" "}"`
echo $RESULT