How to optimize MySQL tables automatically using cron

Busy websites which has a lot of insert/delete transactions may introduce fragmentation in MySQL tables. Fortunately, users and optimize mysql tables with ‘OPTIMIZE TABLE’ command, but how to execute it automatically?

Here’s how:
The mysql-client package in Ubuntu installation comes with a tool called mysqlcheck which is handy for optimizing table in mysql. This command can be executed from bash and can be executed using cron.

to do that, just run this command.

[bash]
cron -e

#in the crontab file– add this line
59 23 * * * /usr/bin/mysqlcheck -o -v -u <mysql username> -h localhost <database_name> -p <password>
[/bash]

This will tell cron to execute mysqlcheck and optimize mysql table of the specified database exactly on 11:59pm, every day. You can change the setting to suit your need.

How to Hide Apache2 and PHP version without using mod_security in Ubuntu Linux

Although security by obscurity is not the best policy to protect your IS assets, but it is still useful to thwarts simple network scanner or newbie crackers.

Note: This tip is written for Ubuntu Linux, the steps is similar to other GNU/Linux distro, albeit with a slight variant.

Hiding Apache2 version
Edit /etc/apache2/apache2.conf

Add these lines at the end of the file:
ServerSignature Off
ServerTokens Prod

Restart Apache2
[bash]
sudo /etc/init.d/apache2 restart
[/bash]

Hiding PHP version
Edit /etc/php5/apache2/php.ini file

Find these lines, and switch it off:
expose_php = Off
display_errors = Off

Additionally you may disable certain ‘risky’ functions in php by editing the disable_functions line:
disable_functions = phpinfo, system,show_source,

Finally, you may restart Apache2 web server.
[bash]
sudo /etc/init.d/apache2 restart
[/bash]

How to back up files periodically using rsnapshot and NFS in Ubuntu Linux

rsnapshot is a utility that uses rsync to synchronize files between two directories. rsnapshot makes it easier for system admin to backup crucial system data files regularly with minimal bandwidth and effort.

This guide assumes that you’ve already installed nfs-client and rsnapshot via “apt-get” utility in your Debian/Ubuntu Linux system.

Assumptions:
The backup server is connected in the same LAN as the main computer. The backup server is mounted as NFS on the main computer, ip address of the backup server is 192.168.1.100.

Step 1: Create a script to mount backup server filesystem
This is to ensure that the backup server is available at least hourly (or daily, depending on your requirements), save the file as “mount-backup-server.sh”

File content:

#!/usr/bin/bash
# mount-backup-server.sh
mount 192.168.1.100:/backup-point/  /media/backup/

Step 2: Ensure the mount script is run hourly

sudo cp mount-backup-server.sh /etc/cron.hourly
sudo chmod a+x /etc/cron.hourly/mount-backup-server.sh

Continue reading “How to back up files periodically using rsnapshot and NFS in Ubuntu Linux”

How to extract Audio from Youtube Flash Video (FLV) in Ubuntu Linux

First you need youtube-dl tool or ‘cclive’ to download the Youtube .FLV file.

Then, download the Youtube stream.
python youtube-dl http://www.youtube.com/watch?v=lee7a55401e

Alternatively, you can use ‘cclive’ to download the youtube stream.
cclive http://www.youtube.com/watch?v=lee7a55401e

After that, use ffmpeg to extract the audio and encode it to MP3
ffmpeg -i lee7a55401e.flv vn -acodec libmp3lame -ab 128000 -ar 44100 lee7a55401e.mp3

Note: You need to install the restricted codecs in order to extract MP3 audio files.

Thanks Mohammad Bahathir Hashim for the tip!

Scientist: How to attribute free software contributions in journal article, proceeding and monograph

Scientists, academicians and researchers are a group of users that benefits greatly from Free and Open Source Software (FOSS / FLOSS). Most them would use free software not only to help in preparing graph and documentation, but also as the main tool in their investigation.

Although it is not explicitly required by the software license or by software authors, the role of free software should be appropriately attributed by academicians and scientists who used them in their investigations as it would not only acknowledge the contribution of free software authors (some of them are hardworking academicians or scientists themselves), but this will also done to fulfill the academic accountability on the researchers part.

Examples on how to attribute Free Software use in Academic Paper
1. Researchers/Academician may cite the software URL and the software author in the “Literature Review/Background”, “Methods”or “Acknowledgement section” in the articles.

2. The citation should include the software release number and the URL to download the software in order to help other researchers to replicate the work (publishing paper is all about guiding others to replicate the investigation)

3. If free software being used as the main tool in the investigation, it would be helpful if the academician/researcher could explain why this particular Free Software is chosen for the research, etc in their journal article or academic papers.

For more examples: Visit the Debian Free Software Guideline, there’s a section about attributing free software in scientific and academic papers.

Give credit to Free Software! Please share this post
If you are an academician or researcher, then please share this post because it will increase awareness about the need to properly attribute free software tools, software author and their role in scientific community.

Thanks!