Sheldon Xu

2012年12月6日

Vim indent tips

摘要: >> Indent line by shiftwidth spaces<< De-indent line by shiftwidth spaces5>> Indent 5 lines5== Re-indent 5 lines>% Increase indent of a braced or bracketed block (place cursor on brace first)=% Reindent a braced or bracketed block (cursor on brace)<% Decrease indent of a brac 阅读全文

posted @ 2012-12-06 10:58 Sheldon Xu 阅读(631) 评论(0) 推荐(0) 编辑

2012年11月24日

Shell: 生成随机字符串

摘要: 生成一个二十位的随机字符串:#!/bin/bashrandstr() { index=0 str="" for i in {a..z}; do arr[index]=$i; index=`expr ${index} + 1`; done for i in {A..Z}; do arr[index]=$i; index=`expr ${index} + 1`; done for i in {0..9}; do arr[index]=$i; index=`expr ${index} + 1`; done for i in {1..20}; do str="$str${ 阅读全文

posted @ 2012-11-24 10:48 Sheldon Xu 阅读(5887) 评论(0) 推荐(1) 编辑

2012年9月24日

强制Apache使用HTTPS

摘要: 如果你想让你的用户访问你的webapp时只使用安全的HTTPS协议,而不是没加密过的HTTP协议,可以这样配置Apache:在<Virtualhost *:80>里面加入如下内容:RewriteEngine OnRewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R,L]然后重启Apache, done! 阅读全文

posted @ 2012-09-24 14:19 Sheldon Xu 阅读(5378) 评论(0) 推荐(0) 编辑

2012年9月17日

执行ssh-add时出现Could not open a connection to your authentication agent

摘要: 若执行ssh-add /path/to/xxx.pem是出现这个错误:Could not open a connection to your authentication agent,则先执行如下命令即可: ssh-agent bash更多关于ssh-agent的细节,可以用 man ssh-agent 来查看 阅读全文

posted @ 2012-09-17 10:07 Sheldon Xu 阅读(90371) 评论(7) 推荐(18) 编辑

2012年6月25日

Shell script: 获取第10+个参数

摘要: 在Shell脚本中,可以用$n的方式获取第n个参数,例如,一个名为paramtest的脚本: #!/bin/bash echo $1 $2执行./paramtest a b 的结果是打印出第1个和第2个参数: a b但是,若脚本需要10个以上的参数,直接写数字会有问题。例如,脚本为: #!/bin/bash echo $1 $2 $3$4$6$7 $8 $9$10执行./paramtest a b c d e f g h i j,结果如下,第10个参数是不对的: a b c d e f g h i a0显然$10被解释成了$1+0。解决方法很简单,第10个参... 阅读全文

posted @ 2012-06-25 10:03 Sheldon Xu 阅读(9518) 评论(0) 推荐(0) 编辑

2012年6月14日

Shell script: 实现include

摘要: 很简单, 用source:#!/bin/bashecho "Begin to call another script..."source /path/to/another/script.sh #其中的变量在caller中依然有效echo "Done" 阅读全文

posted @ 2012-06-14 15:50 Sheldon Xu 阅读(1038) 评论(0) 推荐(0) 编辑

2012年5月28日

设置Archiva使用LDAP验证

摘要: Apache Archiva是一个Maven私服工具,功能完备,和Nexus相比更适合商业使用,它的安装和运行十分简单。Archiva缺省是使用独立的用户验证,但它也支持LDAP验证,要做如下配置 (1.3.5版本):1. 修改<archiva_dir>/apps/archiva/WEB-INF/classes/META-INF/plexus/application.xmlLDAP connection部分的component缺省被注释掉了,把注释去掉,如下: <component> <role>org.codehaus.plexus.redback.com 阅读全文

posted @ 2012-05-28 16:44 Sheldon Xu 阅读(1191) 评论(0) 推荐(0) 编辑

2012年5月22日

Linux: 删除用户密码/禁止登录

摘要: 某些Linux用户(如系统用户)是不应该有密码的,也不应该允许其登录。如果要把某普通用户改成这种用户,或者只是想禁止其登录,可以这样做:(1) 删除用户密码 sudopasswd --delete <username>, 或者 sudo passwd -d <username> 用户没有密码就无法登录了,但设置用户为nologin会更加安全,如下:(2) 设置为nologin sudousrmod -s /sbin/nologin <username>例如,禁止用户tom登录: sudo passwd -d tom sudo usrmod -s /sbin/ 阅读全文

posted @ 2012-05-22 11:29 Sheldon Xu 阅读(6400) 评论(0) 推荐(0) 编辑

2012年5月16日

几个keytool常用命令

摘要: 几个ketool常用的命令写法:1. List: keytool -list -alias -storepass changeit -keystore /usr/lib/jvm/java/jre/lib/security/cacerts2. Import: keytool -import -alias -storepass changeit -file -keystore /usr/lib/jvm/java/jre/lib/security/cacerts3. Delete:keytool -delete ... 阅读全文

posted @ 2012-05-16 13:49 Sheldon Xu 阅读(362) 评论(0) 推荐(0) 编辑

2012年5月14日

Shell script: 获取适配器/IP/子网掩码/网关地址的脚本

摘要: #/bin/bashadapter=$(ifconfig | grep -m1 'encap:Ethernet' | cut -d' ' -f1)echo "Adapter: $adapter"ip=$(ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}')echo "IP: $ip"mask=$(ifconfig | grep 'Mask:'| 阅读全文

posted @ 2012-05-14 15:55 Sheldon Xu 阅读(2091) 评论(0) 推荐(0) 编辑

导航