公司内部一哥们发布到邮件列表中的一个小tip,挺有意思,属于程序员的“奇淫技巧”类吧,值得记录一下。
如果你在linux下工作,那用tail -f跟踪一个日志文件的输出内容应该是家常便饭了。
但是,有时你更关心的是一些敏感字词,希望能够在动态跟踪的同时,把这些字词高亮出来,比如日志中的ERROR关键字。
那么,一种思路就是把你tail输出的东西再做一次包装处理,这个很符合linux管道处理的思想。以高亮Log中的ERROR为例,你可以这样: 浏览全部
公司内部一哥们发布到邮件列表中的一个小tip,挺有意思,属于程序员的“奇淫技巧”类吧,值得记录一下。
如果你在linux下工作,那用tail -f跟踪一个日志文件的输出内容应该是家常便饭了。
但是,有时你更关心的是一些敏感字词,希望能够在动态跟踪的同时,把这些字词高亮出来,比如日志中的ERROR关键字。
那么,一种思路就是把你tail输出的东西再做一次包装处理,这个很符合linux管道处理的思想。以高亮Log中的ERROR为例,你可以这样: 浏览全部
环境要求
PhantomJS is a headless WebKit scriptable with a JavaScript API. It has fast and native support for various web standards: DOM handling, CSS selector, JSON, Canvas, and SVG.
开搞,代码实现如下。
var page = require('webpage').create(); var fs = require("fs"); page.settings.userAgent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit/600.1.3 (KHTML, like Gecko) Version/8.0 Mobile/12A4345d Safari/600.1.4'; page.open('http://ui.ptlogin2.qq.com/cgi-bin/login?pt_no_onekey=1&style=9&appid=1006102&s_url=http%3A%2F%2Fxiaoqu.qq.com%2Fmobile%2Fbarindex.html%3F_lv%3D29313%26_bid%3D128%26_wv%3D1027%26from%3Dshare_link%23bid%3D37469%26type%3D%26source%3Dindex%26scene%3Drecent%26from%3Ddongtai%26webview%3D1&low_login=0&hln_css=http%3A%2F%2Fpub.idqqimg.com%2Fqqun%2Fxiaoqu%2Fmobile%2Fimg%2Fnopack%2Flogin-logo.png', function(status){ if (status == 'success') { page.render('index.png'); setTimeout(function() { page.evaluate(function() { document.getElementById('u').value = 'QQ号码'; document.getElementById('p').value = 'QQ密码'; pt.check(false); //document.getElementById('go').click(); //pt.check()或.click() }); setTimeout(function() { file = fs.open("cookie.log", 'w'); file.write(JSON.stringify(page.cookies)); file.close(); phantom.exit(); }, 2000); }, 1000); } });
cookie会写入到当前目录下的cookie.log文件,有了cookie接下来的事情就简单多了。使用php或js将cookie种到浏览器下即可。
#!/bin/bash #此脚本为自动封ssh登录次数 num=10 #输错密码上限 for i in `awk '/Failed/{print (NF-3)}' /var/log/secure|sort|uniq -c|sort -rn|awk '{if (1>num){print2}}'` do iptables -I INPUT -p tcp -s $i --dport 22 -j DROP done
To obtain the code using Git from the official repository github.com/ariya/phantomjs:
1.1 在服务器上新建想要下载和安装的目录:
如mkdir PhantomJS
1.2 下载PhantomJS安装包
wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
执行结果如下图:
1.3 解压工具包
tar -xjvf phantomjs-2.1.1-linux-x86_64.tar.bz2
执行时报如下错误:
tar (child): cannot run bzip2: No such file or directory
出现上述错误,请安装bzip2
执行指令:
yum -y install bzip2
再次执行解压指令:
成功完成解压。
1.4 将可执行文件放入系统路径
sudo ln -s ~/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/bin/phantomjs
1.5 安装依赖——fontconfig和freetype:
1.6 在终端下测试Phantomjs
注意系统目录为/usr/bin/ 至此成功
sudo apt-get install phantomjs
检查是否正常工作,输入以下命令:
phantomjs --version
若显示当前版本号,则 Phantomjs 安装成功。
Centos 安装v8js
yum install php-pear
yum install re2c
yum install v8-devel
pecl install v8js-0.1.3 // if failed, need to download v8js-0.1.3 and manually install it
// modify b8js.cc and add the blow info line 1
#define PHP_V8_VERSION “0.1.3”
phpize ./configure –with-v8js make make test make install
echo “extension=v8js.so” >> /etc/php.ini
直接pecl install v8js……报错。。
root@ubuntu:/usr/local/src/v8js-1.3.5# ./configure --with-php-config=/usr/local/php7/bin/php-config checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking for a sed that does not truncate output... /bin/sed checking for cc... cc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether cc accepts -g... yes checking for cc option to accept ISO C89... none needed checking how to run the C preprocessor... cc -E checking for icc... no checking for suncc... no checking whether cc understands -c and -o together... yes checking for system library directory... lib checking if compiler supports -R... no checking if compiler supports -Wl,-rpath,... yes checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking target system type... x86_64-unknown-linux-gnu checking for PHP prefix... /usr/local/php7 checking for PHP includes... -I/usr/local/php7/include/php -I/usr/local/php7/include/php/main -I/usr/local/php7/include/php/TSRM -I/usr/local/php7/include/php/Zend -I/usr/local/php7/include/php/ext -I/usr/local/php7/include/php/ext/date/lib checking for PHP extension directory... /usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303 checking for PHP installed headers prefix... /usr/local/php7/include/php checking if debug is enabled... no checking if zts is enabled... no checking for re2c... re2c checking for re2c version... 0.13.5 (ok) checking for gawk... gawk checking for V8 javascript Engine... yes, shared checking for V8 files in default path... found in /usr checking for g++... g++ checking whether we are using the GNU C++ compiler... yes checking whether g++ accepts -g... yes checking how to run the C++ preprocessor... g++ -E checking for C standard version... c++11 checking how to allow c++11 narrowing... checking for libv8_libplatform... checking for libv8_libplatform... configure: error: could not find libv8_libplatform library
系统自带的libv8版本太低了。
sudo add-apt-repository ppa:pinepain/libv8 sudo apt-get update
卸載原先的libv8-dev,執行apt-get install libv8-6.6-dev
nice
Build process completed successfully Installing '/usr/lib/php5/20121212/v8js.so' install ok: channel://pecl.php.net/v8js-0.6.4 configuration option "php_ini" is not set to php.ini location You should add "extension=v8js.so" to php.ini