This is a very useful perl script that i created to know how many user are logged in on FreeRadius from the UNIX/Linux shell or command line.
It’s for FreeRadius with MySQL and I think it is usefull for other radiuses as well.
Below is the full code.
#!/usr/bin/perl -w
use DBI;
my $db = 'radius';
my $db_host = 'localhost';
my $db_username = 'username';
my $db_password = 'password';
my $dbh = DBI->connect("dbi:mysql:database=$db;host=$db_host:port number;user=$db_username;password=$db_password") or die "Couldn't connect to database: $DBI::errstr\n";
my $sql = qq{SELECT DISTINCT UserName,AcctStartTime,FramedIPAddress,CallingStationId FROM radacct WHERE AcctStopTime = '0000-00-00 00:00:00' AND NASIPAddress = '192.168.254.2' GROUP BY UserName};
$sth = $dbh->prepare($sql) or die "Couldn't prepare query '$sql': $DBI::errstr\n";
$sth->execute() or die "Couldn't execute query '$sql': $DBI::errstr\n";
print $sth->rows();
$sth->finish();
$dbh->disconnect();
exit;
Note:
change the username and password to actual username and password of a MySQL database, and NASIPAddress.
Showing posts with label MySQL. Show all posts
Showing posts with label MySQL. Show all posts
Saturday, October 3, 2009
Sunday, March 9, 2008
Reset Forgotten MySQL Root Password
Have you ever forgotten the root password on one of your MySQL servers? No? Well maybe I’m not as perfect as you. This is a quick how to reset your MySQL root password. It does require root access on your server.
First things Log in as root and stop the mysql daemon. Now lets start up the mysql daemon and skip the grant tables which store the passwords.
mysqld_safe --skip-grant-tables
You should see mysqld start up successfully. If not, well you have bigger issues. Now you should be able to connect to mysql without a password.
mysql --user=root mysql
update user set Password=PASSWORD('new-password'); flush privileges; exit;
Now kill your running mysqld, then restart it normally. You should be good to go. Try not to forget your password again.
First things Log in as root and stop the mysql daemon. Now lets start up the mysql daemon and skip the grant tables which store the passwords.
mysqld_safe --skip-grant-tables
You should see mysqld start up successfully. If not, well you have bigger issues. Now you should be able to connect to mysql without a password.
mysql --user=root mysql
update user set Password=PASSWORD('new-password'); flush privileges; exit;
Now kill your running mysqld, then restart it normally. You should be good to go. Try not to forget your password again.
Subscribe to:
Posts (Atom)