Tuesday, September 1, 2009

Adding a new disk to a Linux Fedora machine

as root:
fdisk -l to find the new disk.

You'll get something like this:

Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000a121f

Device Boot Start End Blocks Id System
/dev/sda1 * 1 25 200781 83 Linux
/dev/sda2 26 1044 8185117+ 8e Linux LVM

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000

Disk /dev/sdb doesn't contain a valid partition table


So the new disk is /dev/sdb

To create a new partition:
fdisk /dev/sdb
n (new partition)
p (primary partition)
1 (partition 1)
hit enter (first cylinder)
hit enter (last cylinder)
w (write changes and quit)

now check the new status with
fdisk -l

and now you'll get something like this:

Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000a121f

Device Boot Start End Blocks Id System
/dev/sda1 * 1 25 200781 83 Linux
/dev/sda2 26 1044 8185117+ 8e Linux LVM

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x6fad050b

Device Boot Start End Blocks Id System
/dev/sdb1 1 1044 8385898+ 83 Linux

Now format the new partition
mkfs.ext3 /dev/sdb1

Create a new folder to mount the new partition:
mkdir /disk2

and edit /etc/fstab to mount it after the next reboot adding this line
/dev/sdb1 /disk2 ext3 defaults 1 2

then reboot

Wednesday, April 22, 2009

Tucan: download manager for Rapidshare & Megaupload in Fedora 10



Tucan is a free software written in python to manage downloads and uploads in rapidshare, megaupload etc. It's lightweight, multiplatform and support premium accounts.

You can download it from here

To install it in Fedora 10:
  • install all dependencies: yum install python pygtk2 python-imaging tesseract tesseract-langpack librsvg2
  • unpack the tarball: tar zxvf tucan-.tar.gz
  • cd tucan-
  • as root: make install
  • to launch it (not as root): tucan
  • to uninstall it (as root): make uninstall

Wednesday, April 8, 2009

How to Enable Auto Login on Fedora 10


as root add these lines to /etc/gdm/custom.conf (replacing 'youruser' with your user name)

[daemon]
TimedLoginEnable=true
TimedLogin=youruser


if you want to get an instantaneous login edit /etc/gdm/gdm.schemas and set the the value to 0, the default is 30.


<key>daemon/TimedLoginDelay</key>
<signature>i</signature>
<default>0</default>


reboot your pc

Wednesday, April 1, 2009

From mkv to vob - How to convert a matroska file to dvd in Linux Fedora

  • add the rmp fusion repository. here a simple tutorial to do it.
  • as root install avidemux, and some other useful software: yum install avidemux lame gstreamer-plugins-bad gstreamer-plugins-ugly dvdauthor
  • launch Avidemux: you 'll find a shortcut to Avidemux in your Application Menu -> Sound & Video
  • open your .mkv file. choose "NO" at this message

  • choose "YES" at this message

  • Select Auto -> DVD and click "OK"
  • Select File -> Save -> Save Video... and save it as your_file_name_here.mpeg
  • at the end of the task, create a new xml file with this structure (obviously you have to replace the filename with your mpeg filename) and save it as movie.xml:

    <dvdauthor>
    <vmgm>
    </vmgm>
    <titleset>
    <titles>
    <pgc>
    <vob file="filename.mpeg" />
    </pgc>
    </titles>
    </titleset>
    </dvdauthor>

  • in your terminal move to the folder where you saved the mpeg file
  • not as root dvdauthor -o outputfolder -x movie.xml
  • in outputfolder you'll find AUDIO_TS and VIDEO_TS with the vob files ready to be burned

Monday, March 30, 2009

Diskcheck: Monitoring File Systems on Linux Fedora

the main command to see the file system status is df, that show the system's disk space usage (in kilobyte). if you want a more readable report in megabytes and gigabytes use the command df -h. it's useful to customize this command with the alias command.

if you need to know the size of a specified folder you can use the du command. it will show the size of every subfolder and as last value, the total size. if you only need this last information you can use the command du -hs

Diskcheck is a simple utility that monitors the amount of free disk space on the system and send email to the system administrator when one or more disk drives reach a specified capacity.
You can download it from here
To install it: as root rpm -ivh diskcheck-3.1.1-4.noarch.rpm
This utility is run as an hourly cron task, so you need the crond service running.
You can customize this utility by editing /etc/diskcheck.conf file.

  • defaultCutoff — When disk drives reach this percent capacity, it will be reported. For example, if defaultCutoff = 90, an email will be sent when the monitored disk drives reach 90% capacity.
  • cutoff[/dev/partition] — Override the defaultCutoff for the partition. For example, if cutoff['/dev/hda3'] = 50 is specified, diskcheck will alert the system administrator when the partition /dev/hda3 reaches 50% capacity.
  • cutoff[/mountpoint] — Override the defaultCutoff for the mount point. For example, if cutoff['/home'] = 50 is specified, diskcheck will alert the system administrator when the mount point /home reaches 50% capacity.
  • exclude — Specify one or more partitions for diskcheck to ignore. For example, if exclude = "/dev/sda2 /dev/sda4" is specified, diskcheck will not alert the system administrator if /dev/sda2 or /dev/sda4 reaches the specified cutoff percentage.
  • ignore — Specify one or more file system types to ignore in the format -x filesystem-type. For example, if ignore = "-x nfs -x iso9660" is specified, the system administrator will not be alerted about nfs or iso9660 file systems reaching capacity.
  • mailTo — Email address of the system administrator to alert when partitions and mount points reach the specified capacity. For example, if mailTo = "webmaster@example.com" is specified, webmaster@example.com will be emailed alerts.
  • mailFrom — Specify the identity of the email sender. This is useful if the system administrator wants to filter the mail from diskcheck. For example, if mailFrom = "Disk Usage Monitor" is specified, email will be sent to the system administrator with the sender Disk Usage Monitor.
  • mailProg — Specify the mail program to use to send email alerts. For example, if mailProg = "/usr/sbin/sendmail" is specified, Sendmail will be used as the mail program.

Thursday, March 26, 2009

Gnome schedule - a gui for crontab


GNOME schedule is an excellent graphical crontab manager written in python with pygtk.
to install it in fedora: as root yum install gnome-schedule

you'll find a new entry in your Application Menu > System Tools > Scheduled tasks

Wednesday, March 25, 2009

crontab - scheduled tasks in Linux

crontab is a file which contains the schedule of cron entries to be run and at what times they are to be run.
A cron schedule is a simple ASCII text file. Each user has their own cron schedule. You can edit it only with the crontab command. The default text editor is usually vi

usage:
crontab -e add or edit a scheduled task
crontab -l list the the scheduled tasks
crontab -r remove all scheduled tasks

syntax:
you have 6 positions, 5 for the time, 1 for the command to execute

* * * * * command_to_execute
| | | | |
| | | | |_Weekday 0-6 (0 = Sunday)
| | | |___Month 1-12
| | |_____Day 1-31
| |_______Hour 0-23 (0 = midnight)
|_________Minute 0-59

some example:
30 8 * * * rm /home/{username}/temp/*
this entry remove all files in temp directory every day at 8:30 AM

5,35 * * * 1-5 rm /home/{username}/temp/*
this entry remove all files in temp directory from monday to friday every hour at minute 5 and 35

30 8 * * * rm /home/{username}/temp/* >/dev/null 2>&1
this is the same as the first example but with no email notification and no log file

30 8 * * * rm /home/{username}/temp/* > /home/{username}/logfiles/emptytemp.log >/dev/null 2>&1
this is the same as the first example but with no email notification and the log file redirected to a custom location (> to replace the old log file with the new one, >> to append new log file to old one)

Tuesday, March 24, 2009

a command line tool to download files from rapidshare in Linux


this is a useful simple tool to download files from rapidshare without visual tools. it's perfect if you want download files on your home pc from your office.
you need a valid premium account on rapidshare and wget installed on your pc. to install it: as root yum install wget

create a new directory in your home directory (not as root!):
cd /home/your_user_name
mkdir .cookies
save a cookie in this folder with the following commands:
wget \
--save-cookies ~/.cookies/rapidshare \
--post-data "login=USERNAME&password=PASSWORD" \
-O - \
https://ssl.rapidshare.com/cgi-bin/premiumzone.cgi \
/dev/null

copy and paste the following code and save it as "catchall"

#! /bin/bash
f=`date +%Y-%m-%d_%Hh%Mm%Ss`$RANDOM$RANDOM.log
if [ "$#" = "0" ]
then
echo url missing
else
a="$@"
wget -b -a $f --load-cookies ~/.cookies/rapidshare $a
fi

make it executable and copy it under /usr/bin: as root chmod +x catchall then cp catchall /usr/bin

in your Premium-Zone Settings set as true the option "Direct downloads, requested files are saved without redirection via RapidShare"

now you can download any rapidhare file with the command: catchall your_rapidshare_url_here

you'll get a different log file for each downloaded file. you can see the status of your download with this command: tail -f log_file_name

Monday, March 23, 2009

How to extend Lifetime of a degrading Hard Disk

If one of your hard disks is physically degrading, you can extend its lifetime (while you backup data and prepare to replace the disk) by marking bad blocks and preventing from attempting to store data on them. Assuming an unmounted, ext3 filesystem on /dev/sda1, you can use the following command to perform a non-destructive check for physical failures and then store them in a special inode that the operating system knows to avoid using:

~ e2fsck -cc /dev/sda1

You could also use the badblocks command by its self to write a list of bad blocks to a file and read it into e2fsck with the -l option later.

Friday, March 20, 2009

how to enable ssh on VMware ESXi 3.5


At the console of the ESXi host, press ALT-F1 to access the console window
Enter unsupported in the console and then press Enter
Enter the password for the root login
Edit the file inetd.conf
Uncomment the line that begins with #ssh and save the file
Run the command /sbin/services.sh restart

adding Postgresql yum repository - Fedora 10

download here your rpm
as root: rpm -Uvh 'file_rpm'
cd /etc/yum.repos.d
Edit fedora.repo and fedora-updates.repo [fedora] sections
Add exclude=postgresql* to the bottom of the section.

ctorrent: command line bittorrent client for Fedora

CTorrent is a BitTorrent Client written in C that doesn't require any graphical component, such as an X server.
To install it on Fedora: as root yum install ctorrent

Basic commands: ctorrent -p <port_number> -U <rate_max_upload_Kb> -D <rate_max_download_Kb> <file.torrent>

It's useful to simplify the command with the alias command
If you need to launch it from a remote connection I suggest to use screen command

running 2 vm or more on a low-end server with VMware ESXi 3.5


Error: “Could not power on VM: Admission check failed for memory resource”
Go to Configuration system resource allocation > Click on advanced > Find the VIM object and change the reservation from 512 MB to 192 MB.
_________________________________________________________________________

Error: “Could not power on VM: Admission check failed for cpu resource”

On each virtual machines go to edit settings > Resources Tab. set CPU with a reservation of 0Mhz, and verify that Advanced CPU had Hyperthreaded Cored Shared Mode set to Any.

sar system monitoring tool in Fedora

sar is powerful system monitoring tool but not so easy to configure.
in Fedora you can find it in sysstat package. to install it as root: yum install sysstat

to initialize it, launch as root these commands: /usr/lib/sa/sa1 1 1 and /usr/lib/sa/sa2 -A
now you'll have in /etc/cron.d/sysstat the following commands:

# Run system activity accounting tool every 10 minutes
*/10 * * * * root /usr/lib/sa/sa1 -d 1 1
# 0 * * * * root /usr/lib/sa/sa1 -d 600 6 &
# Generate a daily summary of process accounting at 23:53
53 23 * * * root /usr/lib/sa/sa2 -A

The sa1 script collects and stores binary data in the system activity daily data file, and sa2 writes a daily report in the /var/log/sa/ directory.

Wednesday, March 18, 2009

all-purpose vbs backup script

a simple vbs script that make a daily, weekly and monthly copy of a folder. It maintains 7 days worth of backups.
here's the code:

Dim oFS, backup_dir_w, backup_dir_m, backup_dir_d, backup_sorg
Dim timedir, timedir_del, date_7

'# SET YOUR PATHS HERE ####
backup_sorg = "C:\source_folder"
backup_dir_d = "C:\destination_folder\Daily\"
backup_dir_w = "C:\destination_folder\Weekly\"
backup_dir_m = "C:\destination_folder\Monthly\"

if right(backup_sorg, 1) = "\" then
backup_sorg = Left(backup_sorg, (Len(backup_sorg) - 1))
end if
if right(backup_dir_d, 1) <> "\" then
backup_dir_d = backup_dir_d & "\"
end if
if right(backup_dir_w, 1) <> "\" then
backup_dir_w = backup_dir_w & "\"
end if
if right(backup_dir_m, 1) <> "\" then
backup_dir_m = backup_dir_m & "\"
end if

Set oFS = CreateObject("Scripting.FileSystemObject")

'##### DAILY BACKUP FOLDER ####
timedir = backup_dir_d & Year(Date) & PadZero(Month(Date)) & PadZero(Day(Date)) & "\"
oFS.CreateFolder(timedir)

'#### DAILY FOLDER ####

oFS.CopyFolder backup_sorg, timedir

'#### DELETE 7 DAYS OLD BACKUP ####
date_7 = (DateAdd("d",-7,now()))
timedir_del = backup_dir_d & Year(date_7) & PadZero(Month(date_7)) & PadZero(Day(date_7))

If oFS.FolderExists(timedir_del & "\") Then
oFS.DeleteFolder timedir_del
End If
'################################

timedir = Left(timedir, (Len(timedir) - 1))

'#### WEEKLY BACKUP ####
if WeekDay(Now()) = 6 then
oFS.CopyFolder timedir, backup_dir_w
end if

'#### MONTHLY BACKUP ####
if Day(Now()) = 1 then
oFS.CopyFolder timedir, backup_dir_m
end if
'########################

Set oFS = Nothing

' PadZero - add 0 if value min 10
Function PadZero(val)

If (val < 10) Then
PadZero = "0" & val
Else
PadZero = val
End If

End Function

Tuesday, March 17, 2009

installing PostgreSQL 8 via yum

as root: yum install postgresql postgresql-server
service postgresql initdb then service postgresql start
su - postgres
createuser -P dbadmin
logout

adding rpmfusion repository

for Fedora 8, 9, 10
as root: rpm -Uvh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm

Essential free software:

  • avidemux

  • gstreamer-plugins-ugly

  • gstreamer-plugins-bad

  • lame

  • mplayer (or mpg321)

  • amule

nic bonding on Linux Fedora

as root: first of all disable NetworkManager service and start network service, then create /etc/sysconfig/network-scripts/ifcfg-bond0 and add these lines:

DEVICE=bond0
BONDING_OPTS="mode=1 miimon=100 primary=eth0"
BOOTPROTO=none
ONBOOT=yes
NETWORK=192.168.208.0
NETMASK=255.255.255.0
IPADDR=192.168.208.128


or (if in dhcp configuration)

DEVICE=bond0
BONDING_OPTS="mode=1 miimon=100 primary=eth0"
BOOTPROTO=dhcp
ONBOOT=yes


then edit /etc/sysconfig/network-scripts/ifcfg-eth0 (keeping your HW Address)

DEVICE=eth0
BOOTPROTO=none
HWADDR=00:0c:29:08:b5:19
ONBOOT=no
SLAVE=yes
MASTER=bond0

Repeat the last step for /etc/sysconfig/network-scripts/ifcfg-eth1 :

DEVICE=eth1
HWADDR=00:0c:29:08:b5:23
BOOTPROTO=none
ONBOOT=no
SLAVE=yes
MASTER=bond0


edit /etc/modprobe.conf adding the line:

alias bond0 bonding


restart network service:

/etc/init.d/network restart

a vbs script to backup MySQL db

the script take daily, weekly and monthly backups of all tables in all MySQL databases. It mantains 7 days worth of backups.
here's the code:

Option Explicit

Dim backup_dir, num_days, user, password, arguments, backup_file, backup_dir_daily, backup_dir_weekly, backup_dir_monthly

Dim oShell, oFS, nResults


'SET HERE BACKUP PATH, DAYS OF MYSQL BACKUP, USER AND PWD

backup_dir = "C:\Backup\MySQLBK"

num_days = 7

user = "root"

password = "root"

'#####################################################

Set oFS = CreateObject("Scripting.FileSystemObject")

backup_dir_daily = backup_dir & "Daily"

backup_dir_weekly = backup_dir & "Weekly"


backup_dir_monthly = backup_dir & "Monthly"

If oFS.FolderExists(backup_dir_daily) = False Then

oFS.CreateFolder(backup_dir_daily)

End If

If oFS.FolderExists(backup_dir_weekly) = False Then

oFS.CreateFolder(backup_dir_weekly)

End If

If oFS.FolderExists(backup_dir_monthly) = False Then

oFS.CreateFolder(backup_dir_monthly)

End If

backup_file = backup_dir_daily & Year(Date) & PadZero(Month(Date)) & PadZero(Day(Date)) & "_all_databases.bak"

arguments = "--user=" & user & " --password=" & password & " --all-databases --result-file=" & backup_file

Set oShell = CreateObject("WScript.Shell")

nResults = oShell.Run("mysqldump.exe " & arguments, 1, TRUE)

Set oShell = Nothing

Dim folder, files, file, regex, Matches, Match, counter, backups, i, cur

Set regex = New regexp

regex.Pattern = "[0-9]{8}_all_databases.bak"

regex.Global = True


regex.IgnoreCase = True

Set folder = oFS.GetFolder(backup_dir_daily)

Set files = folder.Files

counter = 0


ReDim backups(0)


For Each file In files

Set Matches = regex.Execute(file.Name)

For Each Match in Matches


Redim Preserve backups(counter)

backups(counter) = Match.Value

counter = counter + 1

Next
Next


cur = 0


For i = counter - 1 To 0 Step -1


If (cur >= num_days) Then



oFS.DeleteFile(backup_dir_daily & backups(i))


Else

End If

cur = cur + 1

Next


'################WEEKLY BACKUP#####################

if WeekDay(Now()) = 6 then

oFS.CopyFile backup_file, backup_dir_weekly


else: end if


'######################################################


'################MONTHLY BACKUP#########################


if Day(Now()) = 1 then

oFS.CopyFile backup_file, backup_dir_monthly

else: end if


'######################################################



Set oFS = Nothing


' PadZero - add "0" to values < 10

Function PadZero(val)

If (val < 10) Then


PadZero = "0" & val

Else

PadZero = val


End If

End Function

a simple gui for rdesktop

rdesktop is an open source command line client for Windows Terminal Services.
to install it in Fedora, as root: yum install rdesktop

RTKdesktop is a simple gui written in perl-Tk.
it need perl and perl-Tk. as root: yum install perl perl-Tk

here's the code:

#!/usr/bin/perl
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
use Tk;
use File::Basename;
use warnings;

my $window = MainWindow->new;
$window->minsize(qw(300 100));
$window->maxsize(qw(300 100));
$window->title("GRdesktop 1.0");
my $ent = $window -> Entry(-textvariable => \$servername, -width => 24, -borderwidth =>2, -relief => 'sunken') -> pack();
$window->Button(-text => "Connect", -width => 18, -command => \&connection )->pack;
$window->Button(-text => "Quit", -width => 18, -command => \&finito )->pack;

MainLoop;

sub connection {
$cmd = "/usr/bin/rdesktop $servername";
system $cmd;
}

sub finito{
exit;
}

screen command - multiple ssh session manager

screen is a multiple ssh session manager.

To install it on Fedora: as root yum install screen
To create a new session: screen -S <session_name>
To list all active sessions: screen -ls
To connect to an active session: screen -r <session_name>
To deattach an active session Ctrl+a then d
To exit an active session Ctrl+a then K or simply exit

All command are case sensitive

alias command

List of alias for current user: alias

Add alias: alias ls="ls -al"

Remove alias: unalias ls