Tag Archives: UNIX

Savings script

So I was thinking about writing a script to calculate the savings over a certain matter of time and came up with the following.

#!/usr/bin/perl

use warnings;
use strict;

print "What is the yield?\n";
my $yield = <>;
print "How many years?\n";
my $years = <>;
print "How much money saved anually?\n";
my $savings = <>;
my $i;
my $new_savings = 0;

for($i = 1; $i <= $years; $i++) {
	$new_savings = $savings + $new_savings;
	$new_savings = $new_savings + $new_savings*($yield/100);
	printf "Savings for year $i are \$%.2f.\n", $new_savings;
}

Below is an usage example.

[19:43:04] xavi@ubuntu:/tmp $ ./yield.pl
What is the yield?
5.0
How many years?
5
How much money saved anually?
10000
Savings for year 1 are $10500.00.
Savings for year 2 are $21525.00.
Savings for year 3 are $33101.25.
Savings for year 4 are $45256.31.
Savings for year 5 are $58019.13.
[19:43:18] xavi@ubuntu:/tmp $

This just gives an idea of the money that can be saved over a short period of time with a five percent yield. It’s a really simple script.

Squeeze is now stable

So squeeze is now stable. Together with the new Debian stable release the guys also updated the website.

I have created a small bash script to perform the upgrade. Here it is.

#!/bin/bash
echo "Moving to /etc/apt"
cd /etc/apt
echo "Backing up sources.list"
cp sources.list sources.list.`date +%F`
echo "Changing the sources for squeeze"
sed 's/lenny/squeeze/g' sources.list > squeeze.sources.list
echo "Copying squeeze to sources.list"
cp squeeze.sources.list sources.list
echo "Performing the upgrade."
apt-get update
apt-get dist-upgrade

Run the script as root or use sudo when executing.

Resulting file should be something like the following.

## main & security repositories
deb http://ftp.us.debian.org/debian/ squeeze main
deb-src http://ftp.us.debian.org/debian/ squeeze main
deb http://security.debian.org/ squeeze/updates main
deb-src http://security.debian.org/ squeeze/updates main

References:

  1. Go2Linux
  2. Linode

‘Access denied for user ‘debian-sys-maint’@’localhost’

So the other day I made an aptitude safe-upgrade and MySQL was upgraded. Thing is I made some changes and when I tried to restart MySQL I saw the following error.

user@server:~$ sudo /etc/init.d/mysql restart
[sudo] password for user:
Stopping MySQL database server: mysqld failed!
Starting MySQL database server: mysqld already running.
/usr/bin/mysqladmin: connect to server at ‘localhost’ failed
error: ‘Access denied for user ‘debian-sys-maint’@’localhost’ (using password: YES)’
user@server:~$

Well fixing this error is fixed changing the password for MySQL user debian-sys-maint. We will retrieve the password from the file /etc/mysql/debian.cnf.


server:~# cat /etc/mysql/debian.cnf
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host = localhost
user = debian-sys-maint
password = password
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
user = debian-sys-maint
password = password
socket = /var/run/mysqld/mysqld.sock
basedir = /usr
server:~#

We backup the MySQL databases.


user@server:~$ mysqldump -u root -p –all-databases > /tmp/backup.sql
Enter password:
user@server:~$

Now lets change the debian-sys-maint password in the database.

mysql>GRANT ALL PRIVILEGES ON *.* TO ‘debian-sys-maint’@’localhost’ IDENTIFIED BY ‘password’ WITH GRANT OPTION;

Now we should be able to safely restart the database server.

user@server:~$ sudo /etc/init.d/mysql restart
[sudo] password for user:
Stopping MySQL database server: mysqld.
Starting MySQL database server: mysqld.
Checking for corrupt, not cleanly closed and upgrade needing tables..
user@server:~$

References:

  1. Ubuntuforums

ASUS 1001P

So I finally bought an ASUS 1001P last month. It came with Windows 7 and I was able to install Ubuntu using wubi. After the installation it didn’t erased anything in the Windows partition. It took 16 GB of an additional extra disk, but still being formated as NTFS. Here is the /etc/fstab output.

[23:51:54] xavi@ubuntu:~ $ cat /etc/fstab 
# /etc/fstab: static file system information.
#
# Use 'blkid -o value -s UUID' to print the universally unique identifier
# for a device; this may be used with UUID= as a more robust way to name
# devices that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
proc            /proc           proc    nodev,noexec,nosuid 0       0
/host/ubuntu/disks/root.disk /               ext4    loop,errors=remount-ro 0       1
/host/ubuntu/disks/swap.disk none            swap    loop,sw         0       0
[23:51:59] xavi@ubuntu:~ $ 

And here goes fdisk.

[23:57:58] xavi@ubuntu:~ $ sudo fdisk -l

Disk /dev/sda: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xabf319e9

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1       13055   104857600    7  HPFS/NTFS
/dev/sda2           13055       29094   128834560    7  HPFS/NTFS
/dev/sda3           29094       30399    10485760   1b  Hidden W95 FAT32
/dev/sda4           30399       30401       17088+  ef  EFI (FAT-12/16/32)
[23:58:03] xavi@ubuntu:~ $ 

This netbook comes with a 250 Gb hard drive and after the Ubuntu installation everything basically works out of the box. One really nice thing is that the wireless works out of the box. From previous experiences I would have to download firmware and recompile the kernel.

The keyboard is a little small, but is quite easy to get used to it. The screen resolution is 1024×600. It can be a little small if you have multiple windows opened, but this gets compensated with the netbooks 2.80 pounds weight.

I`m really happy with this netbook. I was becoming a weight lifter when I walked around with my 12 inch Powerbook.