Quantcast
Channel: Syed Jahanzaib – Personal Blog to Share Knowledge !
Viewing all articles
Browse latest Browse all 409

Bash script to update ‘simultaneous-use’ attribute value in BULK

$
0
0

mysql

Use following script if you want to change ‘Simultanous-Use‘ attribute value for *ALL* users.
I made it for a specific situation and was very successfull.

  • It will check for mysql service running status
  • then it will check mysql radius DB if its accessible ro not,
  • then it will update the attribute value that we define in the script.

All is customizable, do it as per your requirements.


the Script !

#!/bin/bash
# Script to update 'Simultanous-Use' attribute for ALL USERS of radius database 'radcheck' in mysql.
# It was useful in a specific situation.
# 20-Jun-2016
# Syed Jahanzaib
# https://aacable.wordpress.com aacable at hotmail dot com
#set -x
SQLUSER="SQL-USER"
SQLPASS="SQL-PASSWORD
TMPFILE="/tmp/simupdate.txt"
VALUE="2"
DB="radius"
SRV="mysql"
# Check if $SRV (in this case mysql) is running or not, if NOT, then exit the script
SRVSTATUS=$(pgrep $SRV | wc -l);
if [ "$SRVSTATUS" -ne 1 ];
then
echo "-$SRV is down. Pleasec check your $srv service first.
Exiting ...";
exit 1
else
echo "-$SRV is accessible OK. Proceeding further ..."
fi
# Check if $DB (in this case radius ) is accessible or not, if NOT, then exit the script
RESULT=`mysql -u $SQLUSER -p$SQLPASS --skip-column-names -e "SHOW DATABASES LIKE '$DB'"`
if [ "$RESULT" == "$DB" ]; then
echo "-$DB database exist OK. Proceeding further ..."
else
echo "-$DB database does not exist!"
exit 1
fi

# Fethch the ID of simultanous-use attribute
mysql -u$SQLUSER -p$SQLPASS -e "use radius; select * from radcheck;" | grep Simult | awk '{print $1}' > $TMPFILE
echo "
Updating $SRV / $DB table . . ."
# Fetch ID from radcheck table for SIMULTANOUS-USE check
num=0
cat $TMPFILE | while read users
do
num=$[$num+1]
ID=`echo $users | awk '{print $1}'`
mysql -u$SQLUSER -p$SQLPASS -e "UPDATE radius.radcheck SET value = $VALUE WHERE radcheck.id = $ID;"
done
echo "
Script End. All Done"
# END

Filed under: Linux Related

Viewing all articles
Browse latest Browse all 409

Trending Articles