Think before you speak, read before you think.

shell操作mysql一则 | sql update 语句

by

in

背景,打算把radius里有几个用户在凌晨没有人上的时候设为disable,需要用到update语句和at命令

首先在mysql里创建了一个新的帐号,用户名rrr 密码ttt

要操作的数据库为 radius ,操作函数mysql_opt ,操作表radusergroup

#!/bin/bash
#for use:disable the radius users
#author: jpuyy.com
#version:
#history:
#relate on: at mysql|update
sql_user=rrr 
sql_pass=ttt
sql_opt="-u$sql_user -p$sql_pass -s"

mysql_opt() {
db_name=$1
sql_lan=$2
mysql $sql_opt << EOF
USE $db_name;
$sql_lan;
QUIT
EOF
}

data=`mysql_opt radius "UPDATE  radusergroup SET groupname='daloRADIUS-Disabled-Users'  WHERE username in ('aaa','bbb','ccc')"`
echo $data

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *