Saturday, September 18, 2010

Some crontab usages

1. Run a command at boot time
In /etc/crontab add:

@reboot root command

Replace root with username to run as regular user:


@reboot phan vnc4server :1 -geometry 1200x800 &


2. Run GUI programs
To run a GUI program by cron, we have to tell what display should be used by:

DISPLAY=:0 or export DISPLAY=:0

For example, to change fluxbox background automatically twice per hour, at 0 and 30 minute, run crontab -e, then add the following line:

0,30 * * * * DISPLAY=:0 fbsetbg -f -r $HOME/.fluxbox/backgrounds/

Change display number if needed, :0 will be right for most cases.

3. Daily backup to Dropbox at midnight
Run crontab -e, then add:

# run five minutes before midnight, every day
55 23 * * * $HOME/Dropbox/bin/b2d.daily && $HOME/out 2&>1

b2d.daily is a shell script:

$ cat $HOME/Dropbox/bin/b2d.daily


#!/bin/bash
tar czvf $HOME/Dropbox/My-Dir-`date +%F`.tar.gz \
$HOME/My-Dir && DISPLAY=:0 dropbox start

Here we see another way to run GUI programs by cron. Of course, you can use 2 continuous cron jobs, first — run tar, second — dropbox, instead of using b2d.daily script.

P.S. share your cron usages, if there're no top secrets.

Sunday, September 12, 2010

2-Cent Tip: Russian Keyboard Layout in Fluxbox

Russian Keyboard Layout in Fluxbox:

$ cat $HOME/.fluxbox/startup | grep kb
fbxkb &
setxkbmap -layout "us,ru(winkeys)" -option "grp:caps_toggle" -option "grp_led:scroll"

By using winkeys variant we have all keyboard shorcuts (Ctrl+C, Ctrl+V, etc) work.

Saturday, September 11, 2010

Combination of XDrawChem and Inkscape as an open-source molecular editor

There are dozen molecular editor for chemistry and biology [1], but very few of them are open source (or even free for education), and the lasts are feature-limited. Thus, XDrawChem [2] can draw quiet complicated molecules, but draws them not very beautifully. In the other side, this open source program can export images in SVG format, used as default in Inkscape [3], a famous vector editor, which is used to produce very beautiful drawings.

Our action is:
First, draw the molecule (or parts of it) in XDrawChem, then export the image in SVG format:
Draw part of the future molecule (Tinuvin 320) in XDrawChem

Open and edit the SVG file in Inkscape, and don't forget to convert text to path, if you want to edit the file in other system:
Tinuvin 320 (antioxidant)

Finally, save as pdf to use in a LaTeX document, or export to PNG to use in OpenOffice.org.

  1. http://en.wikipedia.org/wiki/Wikipedia:Manual_of_Style_(chemistry)/Structure_drawing
  2. http://xdrawchem.sourceforge.net/
  3. http://www.inkscape.org/

Friday, September 10, 2010

A workaround for OpenOffice.org Draw selection export to PDF

In the current version of OpenOffice.org 3.2, there is still a problem with selection export to PDF in Draw program — the result pdfs always have page dimension of the drawing (A4 or letter) as its paper size (fig. 1). For printing, this is fine, but annoying if you want, for example, include the graphic in a LaTeX document.
Fig. 1. Selection export to PDF bug.
To workaround this problem, change the drawing's page paper to the selection's size in menu Format / Page... then export. The selection's size can be found in the status bar (fig. 2).

Fig. 2. Selection's size in status bar (red stroke).
The result is fig. 3.
Fig. 3. PDF file by workaround.

P.S. Just one more tip: to export OpenOffice.org Calc chart to PDF, copy it to Draw, then...

Thursday, September 02, 2010

Setup a FreeNAS virtual machine in Linux by VirtualBox

We will consider two VirtualBox features — raw hard disk access and VBoxHeadless, to create and run a FreeNAS server "in background" (as a Linux service). It takes us 3 steps.

Step 1. Create and setup (install) a FreeNAS virtual machine with a small hard disk in VirtualBox, network interface is "bridged". The easiest way is using VirtualBox graphical interface. We are not going into details. Just be aware to use so-called "embedded" FreeNAS if you have much of RAM (FreeNAS 0.7.1 requires minimum 192MB). Otherwise install "full version" of FreeNAS and use swap, because the host (Linux) system needs RAM, too.

Step 2. Add raw disk to virtual machine [1].

Step 3. Use VBoxHeadless to run FreeNAS virtual machine without GUI:

$ VBoxHeadless --startvm FreeNAS --vrdp=off >> $HOME/VBoxHeadless.out 2>&1

Read more about VBoxHeadless in VirtualBox documentation [2]. In the command above FreeNAS is the name of created virtual machine, we turn vrdp server off, as FreeNAS has a very powerful Web interface at http://192.168.1.250 by default [3].
You may want to run the virtual machine automatically during boot process. Be aware to run it after vboxdrv service. For this purpose the most convenient solution is /etc/init.d/rc.local. This script run last, but run as root, thus sudo command is used:


$ cat /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.


sudo -H -u phan VBoxHeadless --startvm FreeNAS --vrdp=off >> $HOME/VBoxHeadless.out 2>&1


exit 0

Change phan to your username. The -H option is important, it tell sudo to set HOME environment variable to the home directory of the target user, where VBoxHeadless will find the virtual machine with "FreeNAS" name.

P.S. don't forget to turn off FreeNAS virtual machine before shutdown Linux.

Monday, August 30, 2010

Note about permissions in VirtualBox physical hard disk usage in Linux host

From VirtualBox manual: "Starting with version 1.4, as an alternative to using virtual disk images, VirtualBox can also present either entire physical hard disks or selected partitions thereof as virtual disks to virtual machines...
...this type of access is called "raw hard disk access"; it allows a guest OS to access its virtual hard disk without going through the host OS file system."
Do read the manual (part 9.7.1 at now) and do it at your own risk! Here we will talk only about permission problem you can get in Linux host. That, you will need read/write access for the entire disk (or selected partitions). For example:

$ VBoxManage internalcommands createrawvmdk -filename $HOME/.VirtualBox/HardDisks/sda2.vmdk -rawdisk /dev/sda -partitions 2

set up an image for access /dev/sda2 in Linux host. User needs read/write access to this partition. Otherwise, we will get some messages like this while adding sda2.vmdk to a virtual machine:

NS_ERROR_FAILURE (0x80004005)
Component: 
HardDisk
Interface: 
IHardDisk {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
Callee: 
IVirtualBox {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}

Check the physical disks properties:

$ ls -l /dev/sda*

brw-rw---- 1 root disk 8, 0 2010-08-30 21:53 /dev/sda
brw-rw---- 1 root disk 8, 1 2010-08-30 12:22 /dev/sda1
brw-rw---- 1 root disk 8, 2 2010-08-30 21:31 /dev/sda2
brw-rw---- 1 root disk 8, 5 2010-08-30 12:22 /dev/sda5

We can see one solution to grant permissions is adding username to the disk group, for example, by editing /etc/group file. And don't forget to re-login.

Friday, August 27, 2010

Very short about using transmission-daemon

The transmission-daemon program is a daemon-based Transmission session that can be controlled via IPC commands by transmission-remote(1) [1]. This program is used by default in FreeNAS, and maybe you want to use it on Linux box. It's very likely you distribution come with transmission by default. In that case, you need to install transmission-daemon only:

# apt-get install transmission-daemon


Configuration file is /var/lib/transmission-daemon/info/settings.json (it's quiet safe to add *.*.*.* to rpc-whitelist option). After editing (user, password, paths, etc), we need to reload the daemon itself:

# /etc/init.d/transmission-daemon reload

Using remote client was discussed before [2].
Note: transmission-daemon configuration is very well documented on this web site. You are recommended to read (at least to feel the power of FreeNAS's web interface).

1. man transmission-daemon
2. Cross-platform transmission-remote-gui

Sunday, August 22, 2010

Boot from USB Flash Without BIOS Support Using Plop via GRUB2

As result of an accident the netbook has gone to the heaven in the crisis time, so I've turned FreeNAS box to a normal PC with dual boot (Linux and FreeNAS) for working. Unfortunately, the DVD ROM has gone to the heaven, too. There are not to much options:
  1. Dual boot, each OS on their disk. Needs 2 devices, not my case.
  2. Dual boot on the same disk, still available, but requires skill and time [1].
  3. Boot FreeNAS from USB stick.
The last choice is the most convenient, but BIOS doesn't support booting from USB. Fortunately, there are boot managers, which fill this hole. Plop [2] has many features, many options and well-documented, so I chose it.
The system is running Linux, booted via GRUB2. If you like me don't want to destroy GRUB(2), you can run Plop from GRUB(2). You need to download the program, unzip and copy the boot manager binary program plpbt.bin to /boot, then add the following entry to GRUB2 configuration file (/boot/grub/grub.cfg):

# Boot Plop Boot Manager
menuentry "Plop Boot Manager" {
set root='(hd0,3)' #Change to your boot partition
linux16 /boot/plpbt.bin
}

Hold down Shift key while GRUB2 is booting to get its menu, then you can run Plop, from where FreeNAS on USB Flash can be booted.

See [3] for FreeNAS installation on USB Flash. Get the "embedded" (img) file instead of iso.

P.S. of course this is temporary solution. The better is CF to IDE adapter usage.

1. FreeNAS forum on sf.net
2. Plop boot manager
3. FreeNAS USB installation

Friday, August 20, 2010

Disable unused console (tty) when using Upstart init daemon

There are not /etc/inittab anymore, but /etc/init/ttyN.conf (N from 1 to 6). Just comment out the last line in each file you desire. For example (in /etc/init):

$ cat tty1.conf
# tty1 - getty
#
# This service maintains a getty on tty1 from the point the system is
# started until it is shut down again.

start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]

respawn
exec /sbin/getty -8 38400 tty1

$ cat tty1.conf | wc -l
10

$ sed -i '10 s/^/#/' tty{2,3,4,5,6}.conf

Please tell me other command lines to do the last job.
P.S. in an Ubuntu box Ctrl+Alt+Backspace now is Right Alt (Alt Gr) + Print Screen + k.

Wednesday, August 18, 2010

Boot System Rescue CD from ISO image on the disk with Grub2

"SystemRescueCd is a (Gentoo) Linux system rescue disk available as a bootable CD-ROM or USB stick for administrating or repairing your system and data after a crash." The latest version include many administration tool of both CLI and GUI. If you frequently use SystemRescueCd, you may want to boot it directly from Grub2.
From version 2 GRUB can provide the GREAT loopback option, in co-junction with whom some Linux Live CD distributions (grml, SystemRescueCd, etc) provide direct boot (iso9660) ISO via their options — isofrom, findiso, isoloop and some others. Option isoloop is only supported in SystemRescueCd from version 1.4.0.
The ISO is in (hd0,3)/ISOs/. grub.cfg has the following entry:

# Boot system rescue CD from ISO
menuentry "System Rescue CD from ISO" {
loopback loop (hd0,3)/ISOs/res-1.5.8.iso
linux (loop)/isolinux/rescuecd isoloop=/ISOs/res-1.5.8.iso setkmap=us
initrd (loop)/isolinux/initram.igz
}

grub.cfg contains the global option set root='(hd0,3)', so boot script will search the ISO image in /dev/sda3 partition in the path specified after isoloop option.

Read more:
1. Boot the SystemRescueCD ISO image from the disk using Grub2
2. Boot an ISO via Grub2
3. MultiBoot USB with Grub2 (boot directly from iso files)

Wednesday, March 03, 2010

smartctl -a /dev/ad0

My 250 GB hard disk has gone...

FreeNAS log:
kernel: ad0: FAILURE - READ_DMA48 status=51 error=40 LBA=445600994
kernel: g_vfs_done():ad0p1[READ(offset=228147691520, length=16384)]error = 5

SMART output:

$ smartctl -a /dev/da0
smartctl version 5.38 [i386-portbld-freebsd7.2] Copyright (C) 2002-8 Bruce Allen
Home page is http://smartmontools.sourceforge.net/

=== START OF INFORMATION SECTION ===
Model Family: Seagate Barracuda 7200.9 family
Device Model: ST3250824A
Serial Number: 3ND0Y5G1
Firmware Version: 3.AAH
User Capacity: 250,059,350,016 bytes
Device is: In smartctl database [for details use: -P show]
ATA Version is: 7
ATA Standard is: Exact ATA specification draft version not indicated
Local Time is: Wed Mar 3 15:30:28 2010 MSK
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED

General SMART Values:
Offline data collection status: (0x82) Offline data collection activity
was completed without error.
Auto Offline Data Collection: Enabled.
Self-test execution status: ( 0) The previous self-test routine completed
without error or no self-test has ever
been run.
Total time to complete Offline
data collection: ( 430) seconds.
Offline data collection
capabilities: (0x5b) SMART execute Offline immediate.
Auto Offline data collection on/off support.
Suspend Offline collection upon new
command.
Offline surface scan supported.
Self-test supported.
No Conveyance Self-test supported.
Selective Self-test supported.
SMART capabilities: (0x0003) Saves SMART data before entering
power-saving mode.
Supports SMART auto save timer.
Error logging capability: (0x01) Error logging supported.
General Purpose Logging supported.
Short self-test routine
recommended polling time: ( 1) minutes.
Extended self-test routine
recommended polling time: ( 100) minutes.

SMART Attributes Data Structure revision number: 10
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE
1 Raw_Read_Error_Rate 0x000f 107 095 006 Pre-fail Always - 13692759
3 Spin_Up_Time 0x0003 092 088 000 Pre-fail Always - 0
4 Start_Stop_Count 0x0032 100 100 020 Old_age Always - 342
5 Reallocated_Sector_Ct 0x0033 100 100 036 Pre-fail Always - 0
7 Seek_Error_Rate 0x000f 075 060 030 Pre-fail Always - 38432019
9 Power_On_Hours 0x0032 100 100 000 Old_age Always - 767
10 Spin_Retry_Count 0x0013 100 100 097 Pre-fail Always - 0
12 Power_Cycle_Count 0x0032 100 100 020 Old_age Always - 364
187 Reported_Uncorrect 0x0032 001 001 000 Old_age Always - 1812
189 High_Fly_Writes 0x003a 100 100 000 Old_age Always - 0
190 Airflow_Temperature_Cel 0x0022 060 056 045 Old_age Always - 40 (Lifetime Min/Max 33/40)
194 Temperature_Celsius 0x0022 040 044 000 Old_age Always - 40 (0 19 0 0)
195 Hardware_ECC_Recovered 0x001a 059 051 000 Old_age Always - 76090870
197 Current_Pending_Sector 0x0012 100 100 000 Old_age Always - 2
198 Offline_Uncorrectable 0x0010 100 100 000 Old_age Offline - 2
199 UDMA_CRC_Error_Count 0x003e 200 200 000 Old_age Always - 0
200 Multi_Zone_Error_Rate 0x0000 100 253 000 Old_age Offline - 0
202 TA_Increase_Count 0x0032 100 253 000 Old_age Always - 0

SMART Error Log Version: 1
ATA Error Count: 1817 (device log contains only the most recent five errors)
CR = Command Register [HEX]
FR = Features Register [HEX]
SC = Sector Count Register [HEX]
SN = Sector Number Register [HEX]
CL = Cylinder Low Register [HEX]
CH = Cylinder High Register [HEX]
DH = Device/Head Register [HEX]
DC = Device Command Register [HEX]
ER = Error register [HEX]
ST = Status register [HEX]
Powered_Up_Time is measured from power on, and printed as
DDd+hh:mm:SS.sss where DD=days, hh=hours, mm=minutes,
SS=sec, and sss=millisec. It "wraps" after 49.710 days.

Error 1817 occurred at disk power-on lifetime: 767 hours (31 days + 23 hours)
When the command that caused the error occurred, the device was active or idle.

After command completion occurred, registers were:
ER ST SC SN CL CH DH
-- -- -- -- -- -- --
40 51 00 e8 54 8f 40 Error: UNC at LBA = 0x008f54e8 = 9393384

Commands leading to the command that caused the error were:
CR FR SC SN CL CH DH DC Powered_Up_Time Command/Feature_Name
-- -- -- -- -- -- -- -- ---------------- --------------------
25 00 20 e2 54 8f 40 00 03:27:10.863 READ DMA EXT
b0 d1 01 01 4f c2 e0 00 03:27:08.976 SMART READ ATTRIBUTE THRESHOLDS [OBS-4]
25 00 20 e2 54 8f 40 00 03:27:08.944 READ DMA EXT
b0 d0 00 00 4f c2 e0 00 03:27:07.057 SMART READ DATA
25 00 20 e2 54 8f 40 00 03:27:06.984 READ DMA EXT

Error 1816 occurred at disk power-on lifetime: 767 hours (31 days + 23 hours)
When the command that caused the error occurred, the device was active or idle.

After command completion occurred, registers were:
ER ST SC SN CL CH DH
-- -- -- -- -- -- --
40 51 00 e8 54 8f 40 Error: UNC at LBA = 0x008f54e8 = 9393384

Commands leading to the command that caused the error were:
CR FR SC SN CL CH DH DC Powered_Up_Time Command/Feature_Name
-- -- -- -- -- -- -- -- ---------------- --------------------
25 00 20 e2 54 8f 40 00 03:27:04.672 READ DMA EXT
b0 d0 00 00 4f c2 e0 00 03:27:08.976 SMART READ DATA
25 00 20 e2 54 8f 40 00 03:27:08.944 READ DMA EXT
b0 da 00 00 4f c2 e0 00 03:27:07.057 SMART RETURN STATUS
ca 00 0c 22 2f 00 e0 00 03:27:06.984 WRITE DMA

Error 1815 occurred at disk power-on lifetime: 767 hours (31 days + 23 hours)
When the command that caused the error occurred, the device was active or idle.

After command completion occurred, registers were:
ER ST SC SN CL CH DH
-- -- -- -- -- -- --
40 51 00 e8 54 8f 40 Error: UNC at LBA = 0x008f54e8 = 9393384

Commands leading to the command that caused the error were:
CR FR SC SN CL CH DH DC Powered_Up_Time Command/Feature_Name
-- -- -- -- -- -- -- -- ---------------- --------------------
25 00 20 e2 54 8f 40 00 03:27:04.672 READ DMA EXT
b0 da 00 00 4f c2 e0 00 03:27:04.672 SMART RETURN STATUS
ca 00 0c 22 2f 00 e0 00 03:27:04.672 WRITE DMA
ca 00 20 02 2f 00 e0 00 03:27:07.057 WRITE DMA
ca 00 04 a2 00 00 e0 00 03:27:06.984 WRITE DMA

Error 1814 occurred at disk power-on lifetime: 767 hours (31 days + 23 hours)
When the command that caused the error occurred, the device was active or idle.

After command completion occurred, registers were:
ER ST SC SN CL CH DH
-- -- -- -- -- -- --
40 51 00 e8 54 8f 40 Error: UNC at LBA = 0x008f54e8 = 9393384

Commands leading to the command that caused the error were:
CR FR SC SN CL CH DH DC Powered_Up_Time Command/Feature_Name
-- -- -- -- -- -- -- -- ---------------- --------------------
25 00 20 e2 54 8f 40 00 03:27:04.672 READ DMA EXT
35 00 20 22 19 34 40 00 03:27:04.672 WRITE DMA EXT
35 00 20 02 19 34 40 00 03:27:04.672 WRITE DMA EXT
35 00 20 e2 18 34 40 00 03:27:04.671 WRITE DMA EXT
35 00 20 c2 18 34 40 00 03:27:04.671 WRITE DMA EXT

Error 1813 occurred at disk power-on lifetime: 767 hours (31 days + 23 hours)
When the command that caused the error occurred, the device was active or idle.

After command completion occurred, registers were:
ER ST SC SN CL CH DH
-- -- -- -- -- -- --
40 51 00 e8 54 8f 40 Error: UNC at LBA = 0x008f54e8 = 9393384

Commands leading to the command that caused the error were:
CR FR SC SN CL CH DH DC Powered_Up_Time Command/Feature_Name
-- -- -- -- -- -- -- -- ---------------- --------------------
25 00 20 e2 54 8f 40 00 03:26:51.227 READ DMA EXT
25 00 20 e2 bc 40 40 00 03:26:51.227 READ DMA EXT
ec 00 00 00 00 00 e0 00 03:26:51.226 IDENTIFY DEVICE
25 00 20 e2 54 8f 40 00 03:26:51.226 READ DMA EXT
c8 00 20 62 55 1d e5 00 03:26:51.226 READ DMA

SMART Self-test log structure revision number 1

SMART Selective self-test log data structure revision number 1
SPAN MIN_LBA MAX_LBA CURRENT_TEST_STATUS
1 0 0 Not_testing
2 0 0 Not_testing
3 0 0 Not_testing
4 0 0 Not_testing
5 0 0 Not_testing
Selective self-test flags (0x0):
After scanning selected spans, do NOT read-scan remainder of disk.
If Selective self-test is pending on power-up, resume after 0 minute delay.

Tuesday, February 23, 2010

How to secure your FreeNAS server

Quote from FreeNAS forum:

Q: How do I make sure my FreeNAS server is secure?
A: You can ensure basic security by following the FreeNAS Security Checklist:
  1. Change the WebGUI admin/root password (the default is: freenas)
    Use a very strong password if you intend to access FreeNAS over the Internet.
    Please note - admin/root accounts use the same password.
    Please note - Users that are members of the wheel group can su to root if they know the root password.
  2. Change WebGUI admin user name (the default is admin), to protect your system against dictionary attacks.
  3. DO NOT give shell access to everybody.
  4. DO NOT use FTP over the Internet, use SSH or SFTP instead.
  5. DO NOT enable Password Authentication with SSH, set-up and use SSH key based authentication.
  6. Always use https protocol to access WebGUI interface.
  7. DO NOT open your WebGUI server to internet, rather open a tunnel via SSH from client to server.
 Let's start from the first item:

1. Change the WebGUI admin password under System | General | Password:


2,4. Change WebGUI admin user name and access protocol under System | General:


5,7. SSH setup under Services | SSH:


Of course, you need to create a non-admin user, create SSH key, and upload it to FreeNAS server. Please read SSH manual. If your FreeNAS server is behind a router, you also need to setup the router's NAT:


Here I opened both WebGUI interface and SSH to Internet, but I will use only SSH to connect. To do SSH tunneling from Linux box, type:

$ ssh -v -p 22 -L 8888:localhost:443 username@your.FreeNASorRouter.IP.address

Then open your web browser and type address https://localhost:8888/ and you are there. Windows users can read the instruction in FreeNAS KnowledgeBase.

I don't have a static IP address, so I use (free) DynDNS service.

Last word:

To eliminate Windows users' advantage of using shortcut Linux users can create an alias:


$ cat .bashrc
alias ssh-nas="ssh pvt@192.168.1.250"
alias ssh-dir="ssh pvt@192.168.1.1"
alias tunnel-nas="ssh -v -p 22 -L 8888:localhost:443 tvp@xxx.dyndns.org"
# sudo alias
alias apt-update="sudo apt-get update"
alias apt-install="sudo apt-get install"
alias apt-remove="sudo apt-get remove"
alias mount="sudo mount"
alias umount="sudo umount"
alias suvim="sudo vim"


$ tunnel-nas


Happy using FreeNAS!

Tuesday, February 02, 2010

Bash script for batch renaming of video files, based on the media information

We have a (quiet good) Panasonic miniDV camcorder to save our Little Boy's moments. Software comes with the device can auto index the tape by recoreded date attribute and then batch capture (copy) all the movie to hard disk. It's wonderful feature, except the filenames — we got something like this for every tape:

phan@phan-laptop:/mnt/TQA/Videos/Sushi-1Y/08.03.09-31.05.09$ ls
hsicon.stg     MOVIE0006.avi  MOVIE0012.avi  MOVIE0018.avi  MOVIE0024.avi  MOVIE0030.avi
MOVIE0001.avi  MOVIE0007.avi  MOVIE0013.avi  MOVIE0019.avi  MOVIE0025.avi  MOVIE0031.avi
MOVIE0002.avi  MOVIE0008.avi  MOVIE0014.avi  MOVIE0020.avi  MOVIE0026.avi  MOVIE0032.avi
MOVIE0003.avi  MOVIE0009.avi  MOVIE0015.avi  MOVIE0021.avi  MOVIE0027.avi  TAPE08032009_1902.tap
MOVIE0004.avi  MOVIE0010.avi  MOVIE0016.avi  MOVIE0022.avi  MOVIE0028.avi
MOVIE0005.avi  MOVIE0011.avi  MOVIE0017.avi  MOVIE0023.avi  MOVIE0029.avi


Naturally, it is wanted to rename the movies to show the recorded date and, maybe, some other userful information. Although I like Métamorphose and other batch renaming tools, they can't extract video data. So I decided to create my own bash script. Here is it:

#!/bin/bash
# Bash script for batch renaming of video files, recored by a miniDV-tape
# camcorder, based on the media information (Recorded Date in my case).
# Created by Phan Vinh Thinh, teppi {-} vnoss.org,
# released 01 Feb 2010 under GPL, so feel free to make changes.
# In the script used some echo commands for diagnostic purpose
###############################################################################

# If there is not any given argument (filename), print the help message
if [ $# -eq 0 ]; then
echo "vrename.sh --- Bash script for batch video files renaming";
echo "Usage: ./vrename.sh [files]";
echo "Examples:";
echo -e "\t./vrename.sh *.avi";
echo -e "\t./vrename.sh MOVIE0001.avi MOVIE0002.avi MOVIE0005.avi";
fi;

#for FILE in MOVIE*.avi; do
# $@ expands to all command-line parameters separated by spaces
for FILE in $@; do

# Get the Recorded Date in YYYYMMDDhhmm format and then
# assign to TIME variable
TIME=`mediainfo $FILE | grep -i "recorded date" | cut -d ':' --field=2-3 | \
tr -cd [:alnum:]`;
#echo $TIME;

# Change date format to which we want
    YEAR=${TIME%????????};
    MIN=${TIME#??????????};
    HOUR=${TIME#????????};
    HOUR=${HOUR%$MIN};
    DAY=${TIME#??????};
    DAY=${DAY%$HOUR$MIN};
    MON=${TIME%??????};
    MON=${MON#$YEAR};
#    echo $DAY-$MON-$YEAR-$HOUR-$MIN;

# Change month to short name format (Jan, Feb, etc)
    if [ "$MON" = "01" ] ; then
        Month=Jan;
    elif
    [ "$MON" = "02" ]; then
        Month=Feb;
    elif
    [ "$MON" == "03" ]; then
        Month=Mar;
    elif
    [ "$MON" = "04" ] ; then
        Month=Apr;
    elif
    [ "$MON" = "05" ] ; then
        Month=May;
    elif
    [ "$MON" = "06" ] ; then
        Month=Jun;
    elif
    [ "$MON" = "07" ] ; then
        Month=Jul;
    elif
    [ "$MON" = "08" ] ; then
        Month=Aug;
    elif
    [ "$MON" = "09" ] ; then
        Month=Sep;
    elif
    [ "$MON" = "10" ] ; then
        Month=Oct;
    elif
    [ "$MON" = "11" ] ; then
        Month=Nov;
    elif
    [ "$MON" = "12" ] ; then
        Month=Dec;
    else
        echo "Try without any argument to see help!"
        exit 1;
    fi;
#    echo $Month;

# Assign NAME variable --- basename for future filename
    NAME=Movie-$DAY$Month$YEAR-$HOUR$MIN;
#    echo $NAME;

# Rename FILE to NAME.avi
# Use -i option to make sure there are not 2 files with same NAME
    mv -i -v $FILE $NAME.avi;
done


(To obtain media information, we need an external program — mediainfo).
You can download the script in gzip format from my Google Docs share.

Running script, we got:

phan@phan-laptop:/mnt/TQA/Videos/Sushi-1Y/08.03.09-31.05.09$ ~/vrename.sh *.avi
`MOVIE0001.avi' -> `Movie-08Mar2009-1902.avi'

`MOVIE0002.avi' -> `Movie-08Mar2009-1904.avi'
`MOVIE0003.avi' -> `Movie-08Mar2009-1905.avi'
`MOVIE0004.avi' -> `Movie-08Mar2009-1906.avi'
`MOVIE0005.avi' -> `Movie-08Mar2009-1907.avi'
`MOVIE0006.avi' -> `Movie-16Mar2009-1244.avi'
`MOVIE0007.avi' -> `Movie-16Mar2009-1252.avi'
`MOVIE0008.avi' -> `Movie-16Mar2009-1339.avi'
...

P.S. It's time to start Perl learning ;).

Sunday, January 31, 2010

My first (and maybe last) publication in Russian Academy of Sciences' journal

Podolina E. A., Rudakov O. B., Phan Vinh Thinh, Rudakova L. V. Low-Temperature Liquid Extraction as Sample Preparation of Phenols for reversed-phase HPLC Analysis // Zhurnal Analiticheskoi Khimii (Russian Journal of Analytical Chemistry), 2010, Vol. 65, No. 2, pp. 121–123.
DOI: 10.1134/S1061934810020036

The article is shared by Google Docs.

Saturday, January 23, 2010

Adding more storages to the old-computer-based NAS by PCI SATA controller

As is said before, I'm using my 7-years-old computer to build a NAS run under FreeNAS. It works fine without the need of monitor. The problem is I have only a 250GB IDE hard disk, which doesn't has enough spaces for, growing with my son, home video collection,  and the computer, of course, doesn't have SATA support. At the time of writing (Jan 2010), new IDE hard disks don't have much rooms and cost money, opposite SATA disks now have peak of popularity. There are 1,5TB WD Caviar Green (WD15EADS) for only 4500 rub (~107€), and, you're right, it is wanted.

After reading some forums and wiki the resolve was found — a ST-Lab A-224 PCI SATA150 Controller RTL with 4 SATA II and 2 e-SATA (fig. 1), whose chipset–Silicon Image 3114 is supported by FreeNAS. And fortunately, someone said this controller can work with 1,5TB disks.


Fig. 1. ST-Lab A-224 PCI SATA 150 Controller with 4 SATA II and 2 e-SATA
(click here to see bigger image).

Totally, for the controller, WD15EADS hard disk and Molex-to-SATA power adapter I've paid ~5500 rub (~130€) to obtain a 1,5TB NAS (fig. 2). Beside that, 3 SATA ports are opened for further upgrade...



Fig. 2. A new FreeNAS system with 1,5TB storage.

Note:
1. There is freezing problem of WD15EADS revision 00P8B0 disks (the only model with 3 platters, 500GB each). Everything works good for weeks, month, then the access time will be inconvenient big. Instead of WD15EADS, you can by Samsung Spinpoint F2 EcoGreen (HD154UI). All Samsung HD154UI revisions are 3-platters.
2. Although the controller has manufactured with very high quality, you can't upgrade the firmware, because it uses BIOS instead of flash memory. If you want, you can't change BIOS to flashrom in their service centers.
3. PCI devices (the SATA controller, NIC, etc) share their bus speed (?).