TransNotifo

I use Transmission to download torrents on my headless Linux box.  I was tired of always having to remote into the machine via FreeNX, SSH or web interface to see if downloads had completed. I have been using Notifo for sometime to monitor the lighting on my snakes aquarium and decided that this would be a good use of Notifo once again.  So after a bit of research I came across a bash script example that allowed Transmission to log to a file upon completion of downloads. I then came across a script that would let you send alerts to Notifo from the command line …. So I combined them and was left with the following.



Read More

Adding users from a CSV file to a MySQL database

I recently was hit with an issue where I had to import about 500 employees into a database and having each one added to multiple departments. With the use of an array, I was able to write up some pretty simple code to import a CSV file that simply contained “username, real name” into the database. Thought I would post it in case anyone ever needed to do something along these lines.

<?php
include('../config.php');
$departments = array("department1", "department2", "department3", "department4");
mysql_connect("$dbhost", "$dbuser", "$dbpass") or die(mysql_error());
mysql_select_db("$dbase") or die(mysql_error());
$handle = fopen("employees.csv", "r");
while (($data = fgetcsv($handle, 5000, ",")) !== FALSE) {
    foreach ($departments as &$value) {
        $query = "INSERT INTO employees (`id`, `name`, `realname`, `tickets`, `dept`) VALUES (NULL, '$data[0]', '$data[1]', '0', '$value')";
        $result = mysql_query($query) or die(mysql_error());
        echo $data[1] . ' successfully added to ' . $value . ' department<br>';
    }
}
unset($value);
?>

Auto reconnect to Screen session

I came across this bit of info which makes life easier. Just add this to your .bash_profile and when you SSH to the server it will auto attach to your screen session if you have one running.