都知道如果设置了 MAILTO,cron就会将任务的输出发送给指定邮箱。但如果只想接到错误报警邮件 -- 即任务正常执行时不发送,只在出错时发送 -- 应该怎么实现呢?
方法很简单,指定该任务的标准输出为 /dev/null 就可以了。
MAILTO=mybox@gmail.com 0 1 * * 1 script.sh > /dev/null
原理: MAILTO默认将任务的所有输出发送给指定邮箱。熟悉linux/unix的朋友知道,默认输出包括标准输出和错误输出。所以MAILTO相当于把标准输出和错误输出都定向到邮件服务。当我们人为将标准输出定向到/dev/null, 正常执行的时候,自然不会启用邮件服务,而只在错误输出有内容的时候才启动邮件服务。
How do you install and use rsync to synchronize files and directories from one location (or one server)
to another location? - A common question asked by new sys admin.
rsync is a free software computer program for Unix and Linux like systems which synchronizes files and directories
from one location to another while minimizing data transfer using delta encoding when appropriate. An important feature of rsync not found in most similar programs/protocols is that the mirroring takes place with only one transmission in each direction.
It can perform differential uploads and downloads (synchronization) of files across the network, transferring only data that has changed. The rsync remote-update protocol allows rsync to transfer just the differences between two sets of files across the network connection.
How do I install rsync?
Use any one of the following commands to install rsync. If you are using Debian or Ubuntu Linux, type the following command:
#
apt-get install rsync
OR
$
sudo apt-get install rsync
If you are using Red Hat Enterprise Linux (RHEL) / CentOS 4.x or older version, type the following command:
#
up2date rsync
RHEL / CentOS 5.x or newer (or Fedora Linux) user type the following command:
#
yum install rsync
Since rsync does not provide any security while transferring data it is recommended that you use rsync over ssh session. This allows a secure remote connection. Now let us see some examples of rsync command.
Comman rsync command options- --delete : delete files that don't exist on sender (system)
- -v : Verbose (try -vv for more detailed information)
- -e "ssh options" : specify the ssh as remote shell
- -a : archive mode
- -r : recurse into directories
- -z : compress file data
Copy file from /www/backup.tar.gz to a remote server called openbsd.nixcraft.in
$
rsync -v -e ssh /www/backup.tar.gz jerry@openbsd.nixcraft.in:~
Output:
Password: sent 19099 bytes received 36 bytes 1093.43 bytes/sec total size is 19014 speedup is 0.99
Please note that symbol ~ indicate the users home directory (/home/jerry).
Task : Copy file from a remote server to a local computer
Copy file /home/jerry/webroot.txt from a remote server openbsd.nixcraft.in to a local computer's /tmp directory:
$
rsync -v -e ssh jerry@openbsd.nixcraft.in:~/webroot.txt /tmp
$ rsync -r -a -v -e "ssh -l jerry" --delete /local/webroot openbsd.nixcraft.in:/webroot
Task: Synchronize a remote directory with a local di我的电脑是双系统,刚才我在window下打开在ubuntu中的c文件,发现中文注释出现乱码,如下图
查了查说是因为编码不同,不过也好解决,解决如下:
选择 “高级/配置”, 然后找到 “文件处理”
在文件处理中选择 Unicode/UTF-8检测,勾选自动检测UTF-8文件,然后点击应用,确定,再重新打开文件就可以了。
如下图,正常显示中文了