Monday, May 31, 2010

Fedora automatic login

For the longest time I've been using a timed login in gdm's custom.conf as a kludge to automatically login to my machine at home. But I will be kludging no more! Apparently there is a setting for just such a desire.

Place the following in /etc/gdm/custom.conf, and fedora will boot straight to your desktop.

[daemon]
AutomaticLoginEnable=true
AutomaticLogin=<user name>

Of course, this is completely insecure, but I figure if someome has access to my box at home, I have bigger things to worry about.

Thursday, March 4, 2010

Change the font color on Gnome panels

Thanks to this forum thread at ubuntuforums.org, I discovered how to change the font color on panels in gnome.

In the home directory, create a file called .gtkrc-2.0 and then add the following code:
style "panel"
{
bg[NORMAL] = "#XXXXXX"
fg[NORMAL] = "#XXXXXX"
}
widget "*PanelWidget*" style "panel"
widget "*PanelApplet*" style "panel"
class "*Panel*" style "panel"
widget_class "*Mail*" style "panel"
class "*notif*" style "panel"
class "*Notif*" style "panel"
class "*Tray*" style "panel"
class "*tray*" style "panel"

Replace the #XXXXXX with what ever color your heart desires. Then log out , and when you come back, the font color will be updated.

Have fun!

Tuesday, February 16, 2010

Running Scripts Every 5 Minutes using cron

To run a script every 5 minutes, add the following line into your cron file (using 'crontab -e')

*/5 * * * * /path/to/script


Also, here’s a quick reference for the layout of cron. I suggest pasting this at the top of your cron file.

# MIN HOUR DAYOFMONTH MONTH DAYOFWEEK COMMAND

Standard Deviation in Perl

I recently wanted to figure out the average and standard deviation of a set of values in a perl script. Here's the script I created to do just that:

#!/usr/bin/perl

use strict;
use warnings;

my @my_array = (1,6,9,2,5,12,1);

my $average = average(@my_array);
my $std_dev = std_dev($average, @my_array);

printf "avg=%.2f, st. dev=%.2f\n", $average, $std_dev;

sub average {
my (@values) = @_;

my $count = scalar @values;
my $total = 0;
$total += $_ for @values;

return $count ? $total / $count : 0;
}

sub std_dev {
my ($average, @values) = @_;

my $count = scalar @values;
my $std_dev_sum = 0;
$std_dev_sum += ($_ - $average) ** 2 for @values;

return $count ? sqrt($std_dev_sum / $count) : 0;
}

Wednesday, February 10, 2010

Keeping an ssh Connection Alive

I had the problem where my ssh connection was being dropped after a certain amount of inactivity. It turns out you can set up a config file to counteract this and keep your ssh connections open.

Create a file and set the permissions as follows:

$ touch ~/.ssh/config
$ chmod 600 ~/.ssh/config

Then open the config file and add the line:

ServerAliveInterval 60

This will send a simple request/response signal through the connection after 60 seconds of idle time, preventing a timeout.

Wednesday, February 3, 2010

Creating an ssh Tunnel

This is just what I've done to be able to access a remote database (postgresql in this case) via an ssh tunnel. For a database hosted on the machine I was logging into:

$ ssh -L 63333:localhost:5432 andrew@someserver.com

-L is the port forwarding option for the ssh command. The first port number, 63333, is the local port being bound. The next two values, localhost:5432, are the host and port being bound on the other side of the tunnel, relative to the machine your logging in to. 'andrew@someserver.com' is the normal ssh login username and host.

Now what if the database is hosted on a different machine than the one you're logging into? Just replace 'localhost:5432' with the address and port relative to the machine you've logged into. For example:

$ ssh -L 63333:192.168.1.40:5432 andrew@someserver.com

This command will create a tunnel from port 63333 on my local machine to 192.168.1.40:5432, relative to someserver.com.

After entering one of the above commands, you can now connect to the remote servers by connecting to port 63333 on your local machine and the connection will be protected by ssh.

Restore Fedora's Grub after Windows 7 Install

Installing Windows 7 on a partition on your linux box will overwrite the MBR so that you can no longer boot into your OS of choice. But don't worry because the OS hasn't been harmed in anyway. Here's what I did after finishing the windows install to restore my MBR to allow me to dual boot.

After booting from a Fedora 12 Live CD, open a terminal and get root.

# mkdir /mnt/fedora
# mount /dev/sda3 /mnt/fedora
# mount /dev/sda1 /mnt/fedora/boot
# grub-install --root-directory=/mnt/fedora /dev/sda

These commands mount the fedora root partition and the boot partition if necessary and then write the boot instruction to the MBR. As long as there's no error message, you should be good to go ahead a reboot. You may have to add the windows boot menu option manually.

Add the following to /boot/grub/grub.conf. Be sure to replace (hd0,3) with the appropriate value for your setup.

title windows 7
root (hd0,3)
chainloader +1