You can install jdk in Ubuntu 12.04 by:
sudo add-apt-repository ppa:eugenesan/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
However, when I tried these commands, the installation failed with: Read more…
It is often needed to backup MySQL data to a different server for security issues. Besides, load balance also needs synchronization between MySQL servers. Recently, I’ve set up a synchronization for MySQL server, which serves for an Email system. The following are details for setting up.
1. Preparing for the synchronization
First of all, there is no doubt you need more than two servers. In this pages, the synchronization is used between exact two servers.
Read more…
From: http://hi.baidu.com/vivachn/blog/item/9cf703536fe61a08377abe9b.html
大多数 Linux 命令都会产生输出:文件列表、字符串列表等。但如果要使用其他某个命令并将前一个命令的输出作为参数该怎么办?例如,file 命令显示文件类型(可执行文件、ascii 文本等);你能处理输出,使其仅显示文件名,目前你希望将这些名称传递给 ls -l 命令以查看时间戳记。xargs 命令就是用来完成此项工作的。他允许你对输出执行其他某些命令。记住下面这个来自于第 1 部分中的语法:
例1:
file -Lz * | grep ASCII | cut -d":" -f1 | xargs ls -ltr
让我们来剖析这个命令字符串。第一个,file -Lz *,用于查找是符号链接或经过压缩的文件。他将输出传递给下一个命令 grep ASCII,该命令在其中搜索 “ASCII” 字符串并产生如下所示的输出:
alert_DBA102.log: ASCII English text
alert_DBA102.log.Z: ASCII text (compress’d data 16 bits)
dba102_asmb_12307.trc.Z: ASCII English text (compress’d data 16 bits)
dba102_asmb_20653.trc.Z: ASCII English text (compress’d data 16 bits)
Read more…
tr is a very commonly used utilities tools. In fact, almost everything tr can do can be done by sed. You can consider tr as a simplified sed.
NOTE: tr is a character-oriented tool, instead of a string-oriented one.
There are some scenarios where tr is often used.
1. Change all “abc” in a file to “xyz”
cat file | tr "abc" "xyz" > new_file
You have to notice that, the changes are: ‘a’->’x', ‘b’->’y’ and ‘c’->’z’. NOT “abc”->”xyz” as an entire string.
2. Change all letters to the same case.
Change all letters to upper-case
cat file | tr [a-z] [A-Z] > new_file
Change all letters to lower-case
cat file | tr [A-Z] [a-z] > new_file
Read more…
Sometimes, we need to rename a serial of files. The rename operation may be: 1) Change a certain letter in the file name; 2) Change some consequent letters; 3) Add some letters to the front of the name; 4) Change the case of certain letters; 5) Change the location of some letters.
Now there are methods for doing such things.
1. Change the first letter of a file name
Now I’d like to change first letter of all files to ‘q’.
for i in `ls`; do mv -f $i `echo $i | sed 's/^./q/'`; done
To be clear enough, we write a script instead:
#!/bin/bash
for i in `ls`
do
newfile = `echo $i | sed 's/^./q/'`
mv $i $newfile
done
Read more…
Reference: http://doc.linuxpk.com/80440.html
sed实用工具是一个“编辑器”,但它与其它大多数编辑器不同。除了不面向屏幕之外,它还是非交互式的。这意味着您必须将要对数据执行的命令插入到命令行或要处 理的脚本中。当显示它时,请忘记您在使用 Microsoft Word 或其它大多数编辑器时拥有的交互式编辑文件功能。sed 在一个文件(或文件集)中非交互式、并且不加询问地接收一系列的命令并执行它们。因而,它流经文本就如同水流经溪流一样,因而 sed 恰当地代表了流编辑器。它可以用来将所有出现的 “Mr. Smyth” 修改为 “Mr. Smith”,或将 “tiger cub” 修改为 “wolf cub”。流编辑器非常适合于执行重复的编辑,这种重复编辑如果由人工完成将花费大量的时间。其参数可能和一次性使用一个简单的操作所需的参数一样有限, 或者和一个具有成千上万行要进行编辑修改的脚本文件一样复杂。sed 是 Linux 和 UNIX 工具箱中最有用的工具之一,且使用的参数非常少。
1. sed 的工作方式
sed 实用工具按顺序逐行将文件读入到内存中。然后,它执行为该行指定的所有操作,并在完成请求的修改之后将该行放回到内存中,以将其转储至终端。完成了这一行的所有操作之后,它读取文件的下一行,然后重复该过程直到它完成该文件。如同前面所提到的,默认输出是将每一行的内容输出到屏幕上。在这里,开始涉及到两个重要的因素:首先,输出可以被重定向到另一文件中,以保存变化;第二,源文件(默认地)保持不被修改。sed 默认读取整个文件并对其中的每一行进行修改。不过,可以按需要将操作限制在指定的行上。
Read more…
The minimum timeframe in cron is 1 minute, most cron daemons check every 30 seconds to see if anything needs to be done. However, we often want to run a script every several seconds, take 20 as example.
There are other ways to implement this, and the simple one is as follows. Modify your crontab by:
And add the following lines:
* * * * * /usr/bin/unison webdata
* * * * * sleep 20 && /usr/bin/unison webdata
* * * * * sleep 40 && /usr/bin/unison webdata
Then the unison will run every 20 second.
Often, we need to do some thing like hot backup between two servers. Synchronize files is a commonly used way to do backup. Now we are trying to do a dual-way hot backup by synchronize files.
Synchronization between two directories in the same host is much more simple. Now I’d like to introduce the usage of file synchronization between different hosts.
1. Unison
Unison is a file-synchronization tool for Unix and Windows. It allows two replicas of a collection of files and directories to be stored on different hosts (or different disks on the same host), modified separately, and then brought up to date by propagating the changes in each replica to the other.
Read more…
Utill now, all the services related to email are set up. We have to do some clearup works the let the mail system be easier to use.
1. Set up firewall
Now we could list several ports that should be able to access from outside. They are:
22: SSH
25: Post fix, SMTP service
80: Apache server, http service
110: Courier-pop3, POP3 service
143: Courier-imap, IMAP service
Read more…
Spam has become a very serious problem for mail system. We have to take varies of methods to prevent spam mails.
Now we are to use spam_locker and dspam as our anti-spam tools.
1. Spam_Locker
1.1 Install Spam_Locker
yum install extsuite-slockd
Read more…