giovedì, dicembre 11, 2014

How to change user GID and UID

In certain situation may be helpful to change uid and gid of a particular user in your Ubuntu box. In this case you have first to verify that no process is running with the original user. If there are some have authorized to kill them all. :) Then, run the follow script where substitute the NEWUID and OLDID with yours.
usermod -u <NEWUID> <LOGIN>    
groupmod -g <NEWGID> <GROUP>
find / -user <OLDUID> -exec chown -h <NEWUID> {} \;
find / -group <OLDGID> -exec chgrp -h <NEWGID> {} \;
usermod -g <NEWGID> <LOGIN>

sabato, ottobre 11, 2014

Scite and regular expression


 I don't know if you use Scite editor ( but I use this instead of classic Notepad.

The problem of the day (POD) is to transform a very long list of integer (1 2 3 and so on) adding an apex in prefix and suffix.

Yes yes, I know that there are a lot of solutions for do this, one may be to write an assembly program, but the challenge is to do it fast as possible. Regular expression and Scite can be a good solution. Just copy the list of number, CTRL+H (Replace function), Find: \(\d+\) and Replace: '\1', where 1 is the positional group of regular expression.



mercoledì, ottobre 08, 2014

How to find ram slots info in Linux


this morning I'm looking for a software to find the slot allocation of my servers.

With google I've got a result that is nice and very helpful:

dmidecode -t memory | grep "Size:\|Set:"


mercoledì, settembre 10, 2014

Why I18N and L10N?

I'm currently working on a project developed in Python. I don't know the Python language and for this reason I decided to read a tutorial (I don't know if I'll write something on this topic). Reading I discovered the meaning of symbols I18N and L10N:

  • InternationalizatioN - I18N where 18 refers to the number of letters omitted between "I" and "N";
  • LocalicazioN - L10N where 10 referes to the number of letters omitted between "L" and "N";

Great, I learned something new! :)


venerdì, agosto 08, 2014

MySQL automatic backup

With Ubuntu a sysadmin John can get up a MySQL server with a simple command :
apt-get install mysql
The developer Mark who will use this instance happy be glad to have it available so fast. But tragedy lies behind the door: Mark request to John to restore a copy of yesterday database, but John say to Mark: "You have not made ​​a copy of your database?" reply Mark :"No! You are the sysadmin and you have to do a backup of databases". Mark assume that the John create a periodical backup of all databases in that instance. In this case for John there is a simple tool: AutoMySQLBackup. Install this tool is very simple:
apt-get install automysqlbackup
This is a script to take daily, weekly and monthly backups of your MySQL databases using mysqldump. The backup files will be placed in /var/lib/automysqlbackup which you should rsync somewhere off-site John can sleep safe now. :)

venerdì, giugno 13, 2014

AHA - Ansi HTML Adapter


today i have make a little script in bash that output some colored json on console.
My requirements was to extract the colored output of my script in HTML format.
So, with a little search on Google I have found Ansi HTML Adapter (
And with my surprise it's available on official apt repository.
# apt-get install aha
If you want to test run command:
# ls --color=always | aha --black > ls-output.htm
Very useful. Salvo.

lunedì, giugno 09, 2014

Percentage of memory that is free

Hi, if you want to get a percentage value of free memory on your linux box type this command:
# free | grep Mem | awk '{ printf("free: %.4f %%\n", $4/$2 * 100.0) }'

Repair a placement group in a Ceph cluster

Hi, today i have found an inconsistent placement group on my cluster ceph. For detect number of PG that was not "active+clean" I was run the command:
# ceph pg dump
and then for repair PG:
# ceph pg repair 

martedì, maggio 27, 2014

HowTo Find fiber channel ID (WWN) of a disk/LUN

If you have a privilege to admin a server that is connect via fiber channel with a disk and you want to know channel ID in Ubuntu you have to install sysfsutils :
# apt-get install sysfstools
and then digit
# systool -av -c fc_host | grep "port_name" |awk '{print $NF}'

giovedì, maggio 15, 2014

HowTo save rules of the iptables?

If you need to secure your Ubuntu Server adding some rules on iptables and you want to re-apply rules after a server reboot you can install iptables-persistent

# sudo apt-get install iptables-persistent

After installed, you can save/reload iptables rules anytime:

# sudo /etc/init.d/iptables-persistent save 
# sudo /etc/init.d/iptables-persistent reload

giovedì, maggio 08, 2014

Restore a raw copy of Hyper-V configuration files.

Today I'll try to explain how to recovery Hyper-V VMs from a raw copy of configuration files. My experience start from a new installation of Windows 8 on my notebook.

Before formatting I'v backup C:\ProgramData\Microsoft\Windows\Hyper-V with a raw copy of all files on my external disk. When i'v finished to install all components of my new Windows 8 installation I'v restore the content of previous directory. But when I've launched the Hyper-V console I can't see no VM. At that moment my first question was: Why cannot view VMs if XML files are restored?

Searching with Google I'v found this article when is explained that configuration files have a special permission "NT VIRTUAL MACHINE\{VM_GUID}" to be restored, where {VM_GUID} is the name of XML file.

If you have, like me, a lot of VMs you can use this simple bat script that i write for restore a single VM.

SET VMID=7E3FEDA5-CC67-49FB-8372-23B3F6E1E85D
icacls "%systemdrive%\programdata\Microsoft\Windows\Hyper-V\Virtual Machines\%VMID%.xml" /grant "NT VIRTUAL MACHINE\%VMID%":(F) /L
icacls "%systemdrive%\programdata\Microsoft\Windows\Hyper-V\Virtual Machines\Locks\%VMID%.lock" /grant "NT VIRTUAL MACHINE\%VMID%":(F) /L
net stop vmms
net start vmms

NB: Remember to launch this script as an administrator because it restart the vmms service.

I hope that this article may be useful for you.


giovedì, aprile 24, 2014

Disabling Windows Hibernate function

The method of disabling Hibernate, and thus removing hiberfil.sys, on Windows Vista and up version, is through the command prompt:

powercfg.exe -h off

If you want to turn it on re-enter the command:

powercfg.exe -h on

mercoledì, marzo 05, 2014

HowTo rescan SCSI bus in Ubuntu

If you have a server with a SCSI bus and you want to rescan it you need to install scsi-tools package
# apt-get install scsi-tools
then run the script
# rescan-scsi-bus
and list new scsi devices with
# lsscsi

mercoledì, gennaio 29, 2014

HowTo list last installed package on Ubuntu

Sometimes you install a set of packages on your Ubuntu and if you want to show a ordered list of package you can cat the dpkg log files:
cat /var/log/dpkg.log | grep "\ install\ "