用 sed 和 xargs 把多行合并成一行

每两行合并: 
sed 'N;s/\n/ /' yourFile

多行合并:
cat yourFile|xargs -d'\n'  

针对含有条形码的 CUPS PDF 打印文件的过滤

问题背景: 对于某应用打印出来的文档,“鱼龙混杂”,只需要打印那些含条形码的文档。

解决思路:安装 CUPS PDF,打印到 PDF,针对 PDF 分成单页,用 zbarimg 检测条码,再把检测到条码的单页文件合并成一个 PDF。

使用工具: ImageMagick,zbar

  1. 安装:
    • #yum install ImageMagick
    • #yum install zbar
    • #yum install cups-pdf (version 2.6.1)
  2. 设置 CUPS-PDF 打印机
    • /etc/cups 下根据模板生成一个新的 conf 文件:cups-pdf-shutter.conf,运行 lpinfo -v 便可以看到这个新的 device URI: cups-pdf:/shutter
    • 配置文件设置打印后处理脚本为:PostProcessing /usr/local/bin/cupspdf-shutter.sh
    • 添加打印机:lpadmin -E -p PDF-SHUTTER -v cups-pdf:/shutter -P /etc/cups/ppd/PDF.ppd,重启 cups
  3. 后处理脚本

log () {
echo “`date \”+%b %e %H:%M:%S\”` $1″ >>$LOG
}

LOG=/var/log/cups-pdf.log
PG=”`pdfinfo $1|grep Pages:|awk ‘{print $2}’`”
[ -z “$PG” -o “$PG” = “0” ] && log “Wrong PDF $1 generated” && exit 1

FILENAME=`basename $1`
DIRNAME=`dirname $1`
DATE=`date +”%Y%m%d%H%M%S”`
FILE=”s-“$DATE”.pdf”
DIR=`basename $DIRNAME`

chmod 644 $1
mv $1 $DIRNAME/$FILE

PAGEDIR=`basename $FILE .pdf`
mkdir $DIRNAME/$PAGEDIR
cd $DIRNAME/$PAGEDIR
convert -quiet -background white +matte -monochrome -normalize -density 300 -quality 100 ../$FILE $PAGEDIR.png
[ $? != 0 ] && log “Split $FILE to multiple pages into $DIRNAME/$PAGEDIR failed!” && exit 1
log “Converted $FILE ($PG pages) to multiple pages in $DIRNAME/$PAGEDIR”
for p in `ls $PAGEDIR*.png`; do

SO=`zbarimg -q $p 2>/dev/null|head -1|awk -F: ‘{print $NF}’|sed -e ‘s/[^a-zA-Z0-9_]/_/g;s/ */ /g’`
if [ -n “$SO” ]; then
mv $p “$SO”.png
log “Found Barcode: $SO on $p ”
else
rm $p
fi
done
# Merge all barcode png to one PDF
convert *.png $PAGEDIR-new.pdf
PGNEW=”`pdfinfo $PAGEDIR-new.pdf|grep Pages:|awk ‘{print $2}’`”
mv ../$FILE .
log “New barcode only file $PAGEDIR-new.pdf($PGNEW pages) generated. Saved `expr $PGNEW – $PG` pages.”
rm *.png

解决 CentOS / Redhat /boot 文件系统满,清除旧的内核文件

yum install yum-utils

检查还安装着的所有的内核包:
rpm -q kernel

只保留最后两个:
package-cleanup --oldkernels --count=2

修改 /etc/yum.conf ,设置:
installonly_limit=2

							

Install Odoo 8 on CentOS 7

# yum install centos-release-scl
# yum install python27
# source scl_source enable python27
# pip install --upgrade pip 
# easy_install -U setuptools

  • Install Latest PostgreSQL

yum install pidentd

chkconfig –list|grep post

service rh-postgresql95-postgresql restart su – openerp

vi /var/opt/rh/rh-postgresql95/lib/pgsql/data/pg_hba.conf

service rh-postgresql95-postgresql restart

service xinetd start

chkconfig xinetd on

yum install python27

 

  • Copy Odoo Packages or git clone.

vi /etc/init.d/odoo

chkconfig –add odoo

chkconfig odoo on

service odoo start

  • Install all related Modules

# #####

yum install python-werkzeug python-lxml  python-decorator python-dateutil

pip install -U pytz

ln -s /opt/rh/python27/root/usr/lib64/libpython2.7.so.1.0 /usr/lib64

pip install lxml

pip install decorator

 

pip install python-dateutil –upgrade

# yum install libpq-dev python-dev

pip install psycopg2

yum install python27-python-psycopg2

pip install pyyaml  pillow unittest2 reportlab mako

pip install http://download.gna.org/pychart/PyChart-1.39.tar.gz

pip install psutil requests greenlet gevent

pip install https://pypi.python.org/packages/66/29/9250c6a11822f56a1c2f703e4031d173c5b3725095d3422c11cafcc5427f/psycogreen-1.0.tar.gz

pip install psycogreen

pip install psutils –upgrade

pip install python-openid

pip install pyPdf

yum install cups

yum install cups-devel

pip install pycups

pip install wrapt

pip install xlwt

pip install tinyurl

pip install flanker

pip install passlib

pip install pyldap

yum install python-ldap

yum install openldap-devel

pip install pyldap

pip install googleads

pip install retry

yum install python27-MySQL-python

pip install MySQL-python

pip install egenix-mxodbc

yum install unixODBC-devel

pip install pyodbc

pip install egenix-mx-base egenix-mxodbc-connect-client

echo ok|pip install egenix-pyopenssl

pip install ofxparse

yum install python-lesscpy

yum install nodejs

yum install npm

npm install less -g

npm install -g less-plugin-clean-css

# rpm -ivh /var/tmp/wkhtmltox-0.12.1_linux-centos6-amd64.rpm

# This one line command will download the binary and install to /usr/local, strip the first level wkhtmltox dirname.

# directly install to /usr/local

# cd /usr/local; wget http://download.gna.org/wkhtmltopdf/0.12/0.12.3/wkhtmltox-0.12.3_linux-generic-amd64.tar.xz -O – |xzcat – |tar xvf – –strip 1

命令行自动升级 WordPress 插件

作为个人网站,自动升级插件的风险应该是可控的。 因此用命令行自动升级,可以免除手工下载安装的麻烦。

1. 安装 WP-CLI:

$ curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

$ php wp-cli.phar –info

$ chmod +x wp-cli.phar

$ sudo mv wp-cli.phar /usr/local/bin/wp

更新所有模块:

# wp –allow-root plugin  update –all

另外:

升级 WordPress 核心:

# wp –allow-root core update
Updating to version 4.6.1 (en_US)…
Downloading update from https://downloads.wordpress.org/release/wordpress-4.6.1-new-bundled.zip…
Unpacking the update…

安装新的插件:

# wp –allow-root plugin install https://downloads.wordpress.org/plugin/google-captcha.1.27.zip
Downloading install package from https://downloads.wordpress.org/plugin/google-captcha.1.27.zip…
Unpacking the package…
Installing the plugin…
Plugin installed successfully.

升级主题:

# wp –allow-root theme update –all

[bws_google_captcha]

为 Postfix 配置接收多域名邮件

参考: http://davidsj.co.uk/blog/setup-virtual-domains-in-postfix-without-a-database/

  1. 创建用户,并修改为指定的 uid, gid
    # useradd -m vmail
    # usermod -u 5000 vmail

    # groupmod -g 5000 vmail

  2. 修改 /etc/postfix/main.cf

添加如下行:

virtual_mailbox_domains = /etc/postfix/vhosts.txt
# virtual_mailbox_domains = example1.com, example2.com, example3.com
virtual_mailbox_base = /var/mail/vhosts
virtual_mailbox_maps = hash:/etc/postfix/vmaps.txt
virtual_uid_maps = static:5000 
virtual_gid_maps = static:5000 
virtual_alias_maps = hash:/etc/postfix/valias.txt
virtual_mailbox_maps = hash:/etc/postfix/vmailbox
virtual_minimum_uid = 100
virtual_uid_maps = static:115
virtual_gid_maps = static:115
virtual_alias_maps = hash:/etc/postfix/virtual
vhosts.txt 文件内容为域名列表,每行一个邮件域名
vmaps.txt 文件内容为映射列表,例如:
joe@domain1.internal domain1.internal/joe/
pete@domain2.internal domain2.internal/pete/

可以设置一个全局抓取的地址,使所有那个域名下的邮件都被接收到指定的邮件夹下。
@domain1.internal domain1.internal/catchall/
valias.txt 和 vmaps.txt 类似, 但是可以设置转发到多个目的地,例如:
tom@domain1.internal joe@domain1.internal, pete@domain2.internal
修改完以上文件后,都要对对应的文件做 postmap,以生成对应的 Berkeley DB 文件。 
postmap /etc/postfix/vmaps.txt
postmap /etc/postfix/valias.txt

重启 postfix 后,即可生效。 

配置 Postfix 能从公网接收邮件

修改侦听端口,使能从互联网上接收邮件:

修改 /etc/postfix/main.cf

inet_interfaces = all

然后重启 postfix.

 

 

Postfix SMTP 服务器 邮件队列管理

1. 重新发送队列邮件:

# postfix flush

或者

# postfix -f

 

2. 查看邮件队列:

# mailq

3. 删除所有队列邮件:

# postsuper -d ALL

4. 删除所有等待状态的队列:

# postsuper -d ALL deferred

为 AWS 上的 RHEL 7 添加 php-mbstring 模块

主机从 Godaddy 的虚拟主机,迁移到 AWS 的 EC2 虚拟机,使用 Free Tier 的 RHEL7 Image。 似乎 FreeTier 没有 CentOS 选项。只好选了我不喜欢的 7 版本。 在测试完邮件系统,无误后,把 Freelamp.com 的 DNS 切换到了 AWS 上。

 

登录后台添加文章一看,缺少 php-mbstring 模块。 直接 yum install php-mbstring 没有这个模块。

原来是要先 enable optional yum repo.

先查看一下有那些可用,可以 Enable 的 Repo:

# yum repolist all

然后 Enable 这个 Optional Repo:

# yum-config-manager –enable rhui-REGION-rhel-server-optional

然后就可以安装这个 php-mbstring 包:

# yum install php-mbstring

重启 Apache:

# service httpd restart

Upgrade PCRE from 7 to 8 on CentOS 6.8

Per: http://stackoverflow.com/questions/12212079/pcre-libraries-version-is-too-old

  • Create a file: /etc/yum.repos.d/utter-ramblings.repo

[utter-ramblings]
name=Utter Ramblings
baseurl=http://www.jasonlitka.com/media/EL5/x86_64/
gpgkey=http://www.jasonlitka.com/media/RPM-GPG-KEY-jlitka
enabled=1
gpgcheck=1

  • Install:

# yum –disablerepo=* –enablerepo=utter-ramblings install pcre pcre-devel

  • Restart Apache: #service httpd restart
  • Verify version:

#pcretest -C

PCRE version 8.13 2011-08-16
Compiled with
UTF-8 support
Unicode properties support
Newline sequence is LF
\R matches all Unicode newlines
Internal link size = 2
POSIX malloc threshold = 10
Default match limit = 10000000
Default recursion depth limit = 10000000
Match recursion uses stack

# php -i|grep PCRE
PCRE (Perl Compatible Regular Expressions) Support => enabled
PCRE Library Version => 8.13 2011-08-16

 

Google+