Linux ffmpeg audio conversion – MP3 to FLV

Want to play MP3 files on your website? The best and most common way is using flash video file which compress audio and video better for internet use like YouTube. Here is the instruction I used ffmpeg to convert MP3 to FLV file.

ffmpeg – a program that allow convert audio in numerous formats.

Installing ffmpeg
edit / etc/yum.repos.d/CentOS-Base.repo , add following lines at the end of file

1
2
3
4
[dag]
name=Dag RPM Repository for Centos
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
enabled=1

run this command

1
yum install ffmpeg

Convert MP3 to FLV

1
ffmpeg -y -i /home/song.mp3 -f flv -acodec mp3 -ab 64 -ac 1 /home/song.flv
  • Share/Save/Bookmark

Sending text message (SMS) to your mobile phone from your server via GMail SMTP using PHP

In some cases I need to send a warning message or a notice to my cell phone when certain tasks are done or caught some unexpected errors by server cronjob. This is a quite exciting feature, I don’t need to sit in front of my computer to do the boring monitoring job.

With some googling, there is something called Email to SMS Gateway (here is the gateway list) that allow you to send an Email to phone company, and phone company automatically delivery the Email content as text message to the cell phone owner. In my case, for example, I need to send SMS to cell phone number 416-999-9999 and phone carrier is Rogers. Regarding to the gateway list, means I should send Email to 4169999999@pcs.rogers.com

My first thought about sending out Email is using simple PHP mail() function. Unluckily, the Email sent out couldn’t pass phone carrier’s spam filter (Not exactly know what happened, my guess is my domain can’t pass Reverse DNS checking).

With some googling again for sloving send out Email issue, I found out GMail accounts can actually be used as an SMTP server. If this is working, that means phone carrier directly receive email from GMail.

Here’s a code snippet on how to do it. In the code, I used PHPMailer class.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 
require("class.phpmailer.php");
 
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Host		= "ssl://smtp.gmail.com";
$mail->Port		= "465";
$mail->SMTPDebug  = 2; 
 
$mail->Username = "YOUR_GMAIL_ACCOUNT@gmail.com"; // SMTP username
$mail->Password = "YOUR_GMAIL_LOGIN_PASSWORD"; // SMTP password
 
$from_email = "example@example.com"; //Reply to this email ID
$to_email="4169999999@pcs.rogers.com"; // Recipients email ID
$to_name="to_this_name"; // Recipient's name
 
$mail->From = $from_email;
$mail->FromName = "from_this_name";
$mail->AddAddress($to_email,$to_name);
$mail->AddReplyTo($from_email,"Webmaster");
$mail->WordWrap = 50; // set word wrap
 
$mail->Subject = "TEXT_MESSAGE_SUBJECT";
$mail->Body = "TEXT_MESSAGE_CONTENT"; //HTML Body
$mail->AltBody = "TEXT_MESSAGE_CONTENT"; //Text Body
 
$mail->Send();

Have fun!

Thanks for devsoft to point out this. You must configure PHP to enable php_openssl extension.

  • Share/Save/Bookmark

Simple helloworld c++ program to test noexec tmp partition

1
2
3
4
5
6
7
#include <iostream>
 
int main()
{
  std::cout << "Hello world, compiled with g++ on linux" << std::endl;
  return 0;
}

compile this and move to your secured tmp partition and execute it. If you get a permission error, tmp partition is mounted correctly with noexec.

  • Share/Save/Bookmark

Synchronize linux date and time using ntpdate

ntpdate synchronize and set computers’ date and time via Network Time Protocol (NTP) server(s).

1
/usr/sbin/ntpdate -u 0.fedora.pool.ntp.org

0.fedora.pool.ntp.org is NTP server. If this server is not working, find another one.

  • Share/Save/Bookmark

Download all file recursively from ftp server

ncftpget is able to let you download entire ftp directory and sub directories from remote ftp server.

Install ncftp client

1
yum install ncftp

Start downloading

1
ncftpget -R -v -u "username"  -p "userpassword" ftp.someserver.com /home/save_at_here /downloads

where,

  • -R : download all subdirectories and files (recusive)
  • -v : verbose, show download activity
  • -u : ftp server user name
  • -p : ftp server user login (if skipped, will prompt to ask password)
  • ftp.someserver.com : ftp server domain or IP
  • /home/save_at_here : all downloaded file will save in this directory
  • /downloads : remote ftp server directory you wish to copy
  • Share/Save/Bookmark

Backup MySQL databases to remote server using mysql-zrm

Recently I use mysql-zrm to backup a large databases from a client server. I can backup all databases or a set of database or maybe some of tables with one line linux command. Pretty easy to use.

You may imagine that mysql-zrm is a strong management tool of mysql, mysqldump and mysqlhotcopy.  The key benifits for me are : I can backup all databases at once with my databases are automatically created if a new client comes; mysql-zrm is able to save compressed data to different folder, so I can keep saved data up to seven days (you may do it one month or maybe one year); It also has a scheduler to do your task every certain time you want.

Installation:

1. login to your backup server

2. Download rpm from http://www.zmanda.com/download-zrm.php

3. If you don’t have Perl installed, run ” yum install perl ”

4. run ” rpm -ivh MySQL-zrm-2.0-1.noarch.rpm ”

5. “  vi /etc/mysql-zrm/mysql-zrm.conf ” update following parameters in file

backup-mode=logical [ ideally raw for myisam engine and logical for innodb. but I recommend using logical for default. Because when I use raw for default value, and if there is table with innodb engine exist, zrm will prompt me password for mysql@(server_ip) which have no idea about linux mysql user login ]

destination=/home/mybackup_dir  [ specify where backup files will be stored]

Start backup:

mysql-zrm –action backup –host xxx.xxx.xxx.xxx –user aabb –password ccdd  –backup-set abcd

where
–host is remote server IP for MySQL
–user is remote MySQL server  user login
–password is remote MySQL server  user login password
–backup-set is backup folder name

Result:

after running the command, you will get backup file in the path look like this

/home/mybackup_dir/abcd/20081128195236

Restore database to local server:

/usr/bin/mysql-zrm-restore –user=1122 –password=2233 –source-directory=/home/mybackup_dir/abcd/20081128195236
check out your backup server MySQL database. :-)

  • Share/Save/Bookmark

Install VMware tools to Fedora 10 client OS on Windows Vista host OS

Software requirements:

  • Windows Vista Ultimate 64bit
  • VMware workstation 6.5.1
  • Fedora 10 64bit

Install packages that are required to build VMware tools:

1
 yum install gcc make kernel-devel</li>

Step by step guide

  1. Logon to Fedora, and select “Install VMware Tools” from VM menu
  2. After the tool cd was mount, open a terminal window logon as root user and type
    1
    2
    3
    
    cd ~
    mkdir VMware
    cd VMWare
  3. Type:
    1
    
    cp /media/VMware\ Tools/VMwareTools-7.8.4-126130.tar.gz ./
  4. Untar and install by typing:
    1
    2
    3
    
    tar zxpf ./VMwareTools-7.8.4-126130.tar.gz
    cd vmware-tools-distrib/
    ./vmware-install.pl
  5. Config and build VMware tool modules:
    1
    
    vmware-config-tools.pl

    and type y when prompt to build vmware modules

Restart your guest OS and then you should have vmware tool installed. You should be able to see your shared folder from the host OS.

  • Share/Save/Bookmark

Linux Server Security Checklist

  • Firewall (apf/csf and bfd)
  • Secure tmp partition (noexec)
  • rootkit scanning
  • PHP hardening
  • Apache hardening
  • Mod-security
  • Shell login notification
  • Share/Save/Bookmark

Troubleshooting Linux High CPU Utilization

troubleshooting linux high cpu utilization

1. us -> User CPU time: The time the CPU has spent running users’
processes that are not niced.
2. sy -> System CPU time: The time the CPU has spent running the
kernel and its processes.
3. ni -> Nice CPU time: The time the CPU has spent running users’
proccess that have been niced.
4. wa -> iowait: Amount of time the CPU has been waiting for I/O to complete.
5. hi -> Hardware IRQ: The amount of time the CPU has been servicing
hardware interrupts.
6. si -> Software Interrupts.: The amount of time the CPU has been
servicing software interrupts.

ps -eo pcpu,pid,user,args | sort -k 1 -r | head -10

  • Share/Save/Bookmark

Firefox Version 3.0.3 Self-signed Certificate Problem

I often upgrade Firefox to the latest versions with only conditions: google toolbar, Web Developer extension and Firebug extension supports.

I never ran into problems except with this latest version: 3.0.3

The problem: Websites with self-signed certificate are no longer working. It doesn’t give me the option to add exceptions like it used to be. (websites with exceptions added in previous versions are not effected.)

Tried this:
Go to Tools -> Option menu, select Advanced, on Encription tab click on View Certificates.
Go to Servers tab in Certificate Manager, click on Add Exception
Enter the host (https://localhost) then click on Get Certificate button.
Same problem

After some searching, some are saying to re-set one of Firefox settings in about:config. However it doesn’t work in my case.

I gave it another try in the Certification Manager by use the host name with port number. It worked!

I am glad it worked out and I don’t need to go back to 3.0.2 or wait for fix in the next version.

  • Share/Save/Bookmark