CentOS 6 (74)

How To scp, ssh and rsync without prompting for password

Whenever you need to use scp to copy files, it asks for passwords. Same with rsync as it (by default) uses ssh as well. Usually scp and rsync commands are used to transfer or backup files between known hosts or by the same user on both the hosts. It can get really annoying the password is asked every time. I even had the idea of writing an expect script to provide the password. Of course, I didn't. Instead I browsed for a solution and found it after quite some time. There are already a couple of links out there which talk about it. I am adding to it... Lets say you want to copy…
Read more...

SELinux 导致 PHP 无法使用 fsockopen 连接到 Memcached 服务器

前段时间刚刚写了一篇关于 SELinux 导致 httpd(Apache2) 无法启动 的文章,今天又碰到 SELinux 的问题了。 事情是这样的: 首先是服务器硬盘出问题了:-(,我给换了块硬盘,然后重装系统(CentOS 5.4 i386),然后安装各种程序、还原各种数据。最后一步是使用 memcache.php 来监控 Memcache 状态。然而却发现该工具无法连接上 Memcached 服务器。经检查,Memcached 服务器已经正常启动,使用 telnet 能够正常连接上去,使用 Memcached 的应用程序(PHP程序)也正常工作。查看 memcache.php 代码发现其是使用 fsockopen 来连接 Memcached 服务器,遂怀疑 Socket 扩展的问题。然而,检查发现可以在命令行中使用 fsockopen 连接到任意地址的任意端口,说明 Socket 扩展没问题。但在 httpd 中使用 fsockopen 来就只能连接本机的 80、8080、443 端口,连接其他端口均失败。 检查 httpd 的 log 也没发现任何问题。上网搜索也没发现类似问题,郁闷ing…… 于是又想到是否是 SELinux 的问题。grep 了下 /var/log/audit/audit.log,发现以下线索: [liang@www ~]$ sudo grep denied /var/log/audit/audit.log type=AVC msg=audit(1280882021.681:780): avc:  denied  { name_connect } for  pid=3822 comm="httpd" dest=11211 scontext=user_u:system_r:httpd_t:s0 tcontext=system_u:object_r:http_cache_port_t:s0 tclass=tcp_socket type=AVC msg=audit(1280885410.800:805): avc:  denied  { name_connect } for  pid=3790 comm="httpd" dest=11211 scontext=user_u:system_r:httpd_t:s0 tcontext=system_u:object_r:http_cache_port_t:s0 tclass=tcp_socket 看来又是 SELinux 搞的鬼。继续检查,发现 /var/log/messages 有以下错误信息: 4 08:11:59 www setroubleshoot: SELinux is preventing the http daemon from connecting to the itself…
Read more...

What does --pesize=32768 means?

  Physical Extents (PE) are 32KiB:  http://www.redhat.com/docs/manuals/enterprise/RHEL-5-manual/Installation_Guide-en-US/s1-kickstart2-options.html"--pesize= â Set the size of the physical extents"
Read more...

Log iptables Messages to a Separate File with rsyslog

Log iptables Messages to a Separate File with rsyslog Firewall logging is very important, both to detect break-in attempts and to ensure that firewall rules are working properly. Unfortunately, it’s often difficult to predict in advance which rules and what information should be logged. Consequently, it’s common practice to err on the side of verbosity. Given the amount of traffic that any machine connected to the Internet is exposed to, it’s critical that firewall logs be separated from normal logs in order to ease monitoring. What follows are two methods to accomplish this using iptables on Linux. The first method…
Read more...

Force iptables to log messages to a different log file

Force iptables to log messages to a different log file NIXCRAFT on OCTOBER 3, 2006 · 38 COMMENTS· LAST UPDATED FEBRUARY 23, 2008 IPTABLES, LINUX, MONITORING According to man page:Iptables is used to set up, maintain, and inspect the tables of IP packet filter rules in the Linux kernel. Several different tables may be defined. Each table contains a number of built-in chains and may also contain user defined chains. By default, Iptables log message to a /var/log/messages file. However you can change this location. I will show you how to create a new logfile called /var/log/iptables.log. Changing or using a new file allows you to create better…
Read more...

Shell 之 column 格式化输出日志文件 整齐

最近在调整一个脚本脚本,在cygwin下,脚本输出的日志杂乱,看起来很费劲。想对输出进行排序,由于列的宽度都是不固定的,所以操作起来很吃力,怎么都调整不好。 后来找到一个命令,非常好用   那就是:column -t filename 先前输出的日志如下: 乱的像一团麻一样,看起来非常吃力。 使用column 之后如下: 整整齐齐,一目 了然,在脚本使用,输出也是非常清爽
Read more...

【Shell脚本】逐行处理文本文件

经常会对文体文件进行逐行处理,在Shell里面如何获取每行数据,然后处理该行数据,最后读取下一行数据,循环处理.有多种解决方法如下: 1.通过read命令完成. read命令接收标准输入,或其他文件描述符的输入,得到输入后,read命令将数据放入一个标准变量中. 利用read读取文件时,每次调用read命令都会读取文件中的"一行"文本. 当文件没有可读的行时,read命令将以非零状态退出.   1 cat data.dat | while read line 2 do 3 echo "File:${line}" 4 done 5 6 while read line 7 do 8 echo "File:${line}" 9 done < data.dat   2.使用awk命令完成 awk是一种优良的文本处理工具,提供了极其强大的功能. 利用awk读取文件中的每行数据,并且可以对每行数据做一些处理,还可以单独处理每行数据里的每列数据. 1 cat data.dat | awk '{print $0}' 2 cat data.dat | awk 'for(i=2;i<NF;i++) {printf $i} printf "\n"}' 第1行代码输出data.dat里的每行数据,第2代码输出每行中从第2列之后的数据. 如果是单纯的数据或文本文件的按行读取和显示的话,使用awk命令比较方便. 3.使用for var in file 命令完成 for var in file 表示变量var在file中循环取值.取值的分隔符由$IFS确定.   1 for line in $(cat data.dat) 2 do 3 echo "File:${line}" 4 done 5 6 for line in `cat data.dat` 7 do 8 echo "File:${line}" 9 done   如果输入文本每行中没有空格,则line在输入文本中按换行符分隔符循环取值. 如果输入文本中包括空格或制表符,则不是换行读取,line在输入文本中按空格分隔符或制表符或换行符特环取值. 可以通过把IFS设置为换行符来达到逐行读取的功能. IFS的默认值为:空白(包括:空格,制表符,换行符).
Read more...

怎么把命令输出结果赋值给变量(已解决)

我要把awk '/eth0/{print $1 }' /proc/net/dev |sed 's/eth0://'输出的结果赋值给变量 input 搞定了input=$(awk '/eth0/{print $1 }' /proc/net/dev |sed 's/eth0://')       awk '/eth0/{print $1 }' /proc/net/dev |sed 's/eth0://'不能用一个句子写出来?awk -F "[: ]+" '/eth0/{print $3}' /proc/net/dev     http://cu.img168.net/static/image/common//icon_quote_e.gif); line-height: 1.6; zoom: 1; background-position: 100% 100%; background-repeat: no-repeat no-repeat;">假如一个命令ls有3个输出1,2,3;我如何把1,2,3分别赋值给VAR1,VAR2,VAR3呢? #bash /home/lee#ls [0-9] 1  2  3 /home/lee#while read file;do ((++n));eval var$n=$file;done< <(ls [0-9]) /home/lee#echo $var1 1 /home/lee#echo $var2 2 /home/lee#echo $var3      
Read more...

grep 正则表达式选项要记得转义

使用过程中,使用最多的参数就是 -v ,但是用着并不爽。 比如说,我想查找一个单词“UserService”,但是像”*.svn” 这种文件就不用显示了,我该怎么做呢? grep -r "UserService" ./ | grep -v "svn" 但是,如果类似于含有”test、auto_load”之类的文件我也不显示,怎么做呢?我之前的做法是: grep -r "UserService" ./ | grep -v "svn" | grep -v "test" | grep -v "auto_load" 命令很长,而且麻烦,于是就想,grep本身是按照正则表达式来当做选项的,那么我是不是可以利用到正则表达式的“或|”命令? grep -r "UserService" ./ | grep -v "svn|test|auto_load" 很显示,执行结果显示上面的命令不符合我的需求,于是苦思不得其解。原来,在使用正则表达式选项时,要记得将”|”转义。最终命令如下: grep -r "UserService" ./ | grep -v "svn\|prj\|test\|auto_load"
Read more...

( ! ) Warning: count(): Parameter must be an array or an object that implements Countable in /var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/com_k2/templates/default/category.php on line 191
Call Stack
#TimeMemoryFunctionLocation
10.0003413624{main}( ).../index.php:0
20.29524263952Joomla\CMS\Application\SiteApplication->execute( ).../index.php:49
30.29524263952Joomla\CMS\Application\SiteApplication->doExecute( ).../CMSApplication.php:196
40.872511454000Joomla\CMS\Application\SiteApplication->dispatch( ).../SiteApplication.php:233
50.873511478280Joomla\CMS\Component\ComponentHelper::renderComponent( ).../SiteApplication.php:194
60.874411533608Joomla\CMS\Component\ComponentHelper::executeComponent( ).../ComponentHelper.php:377
70.874711561008require_once( '/var/www/vhosts/shan.info/httpdocs/components/com_k2/k2.php' ).../ComponentHelper.php:402
80.884911896200K2ControllerItemlist->execute( ).../k2.php:64
90.884911896200K2ControllerItemlist->display( ).../BaseController.php:710
100.930412803144K2ControllerItemlist->display( ).../itemlist.php:49
110.930412803144K2ControllerItemlist->display( ).../controller.php:19
120.934213017408Joomla\CMS\Cache\Controller\ViewController->get( ).../BaseController.php:663
130.986113038096K2ViewItemlist->display( ).../ViewController.php:102
141.363716190200K2ViewItemlist->display( ).../view.html.php:1407
151.363716190200K2ViewItemlist->loadTemplate( ).../HtmlView.php:230
161.384816258672include( '/var/www/vhosts/shan.info/httpdocs/templates/gk_publisher/html/com_k2/templates/default/category.php' ).../HtmlView.php:701