存档

‘Shell’ 分类的存档

使用enca转换文件编码

2010年7月8日 16hot 没有评论

安装enca:

# cd /usr/ports/converters/enca
# make install clean

对一个目录下的文件进行转换编码:

# find . -type f | grep -E -v “.svn|.gif|.jpg|.png” | xargs enca -L zh_CN -x UTF-8

分类: BSD/linux, Shell 标签: , ,

使用rxvt-unicode

2010年5月30日 16hot 没有评论

在新笔记本,迁移到UTF-8环境下,mrxvt不支持UTF-8,中文显示乱码。只有换成rxvt-unicode了。支持UTF-8,中文输入。

配置文件:

$ cat ~/.Xresources
Xft.dpi:96
! Color setting
!URxvt.geometry: 200×53
URxvt.cursorColor:green
URxvt.foreground:black
URxvt.background:lightyellow
! transparent setting
URxvt.inheritPixmap:false
URxvt.tintColor:lightyellow
URxvt.shading:-80
! normal setting
URxvt.termName:rxvt
URxvt.cursorBlink:true
URxvt.saveLines:65535
URxvt.scrollBar_right:true
URxvt.scrollTtyKeypress:true
URxvt.scrollWithBuffer:false
!URxvt.font:xft:serif:pixelsize=13:antialias=false
!URxvt.font: 9x15bold,\
! -misc-fixed-bold-r-normal–15-140-75-75-c-90-iso10646-1,\
! -misc-fixed-medium-r-normal–15-140-75-75-c-90-iso10646-1,\
! [codeset=cp936]xft:serif:antialias=false, \
! xft:simsun:antialias=false

URxvt.font: -*-fixed-medium-r-*–14-*-*-*-*-*-iso10646-1,\
xft:simsun:pixelsize=14:antialias=false

! test modify ALT key value
!URxvt.insecure:true
!URxvt.modifier:alt
!URxvt.meta8:true
!XTerm*VT100*metaSendsEscape:true
urxvt*font:xft:SimSun:pixelsize=16
urxvt*imFont: -misc-simsun-medium-r-normal-0-0-0-0-p-0-iso10646-1
urxvt*inputMethod:SCIM
urxvt*preeditType: OverTheSpot
urxvt*multichar_encoding:noenc

分类: BSD/linux, Shell 标签: ,

shell脚本编译

2010年5月18日 16hot 没有评论

今天发现一个好玩的东东,可以将shell脚本编译一下。

http://www.datsi.fi.upm.es/~frosal/sources/shc.html

文档:

Manpage for shc(1)


NAME

     shc - Generic shell script compiler

SYNOPSIS

     shc [ -e date ] [ -m addr ] [ -i iopt ] [ -x cmnd ]
     [ -l lopt ] [ -ACDhTv ] -f script

DESCRIPTION

     shc creates a stripped  binary  executable  version  of  the
     script specified with -f on the command line.

     The binary version will get a .x extension appended and will
     usually  be  a  bit  larger  in size than the original ascii
     code. Generated C source code is saved in a  file  with  the
     extension .x.c

     If you supply an expiration date with the -e option the com-
     piled  binary  will  refuse to run after the date specified.
     The message "Please contact your provider" will be displayed
     instead.  This message can be changed with the -m option.

     You can compile any kind of shell script, but  you  need  to
     supply valid -i, -x and -l options.

     The compiled binary will still be  dependent  on  the  shell
     specified  in  the  first  line  of  the  shell  code  (i.e.
     #!/bin/sh), thus shc does not create completely  independent
     binaries.

     shc itself is not a compiler such as cc, it  rather  encodes
     and encrypts a shell script and generates C source code with
     the added expiration capability. It  then  uses  the  system
     compiler  to compile a stripped binary which behaves exactly
     like the  original  script.  Upon  execution,  the  compiled
     binary  will  decrypt and execute the code with the shell -c
     option.  Unfortunatelly, it will  not  give  you  any  speed
     improvement as a real C program would.

     shc's main purpose is to protect  your  shell  scripts  from
     modification  or  inspection.  You can use it if you wish to
     distribute your scripts but don't want  them  to  be  easily
     readable by other people.

OPTIONS

     The command line options are:

     -e date
          Expiration date in dd/mm/yyyy format [none]

     -m message
          message to display  upon  expiration  ["Please  contact
          your provider"]

     -f script_name
          File name of the script to compile

     -i inline_option
          Inline option for the shell interpreter i.e: -e

     -x comand
          eXec    command,    as    a    printf    format    i.e:
          exec(\\'%s\\',@ARGV);

     -l last_option
          Last shell option i.e: --

     -r   Relax security. Make  a  redistributable  binary  which
          executes  on different systems running the same operat-
          ing system.

     -v   Verbose compilation

     -D   Switch on debug exec calls

     -T   Allow binary to be  traceable  (using  strace,  ptrace,
          truss, etc.)

     -C   Display license and exit

     -A   Display abstract and exit

     -h   Display help and exit

ENVIRONMENT VARIABLES

     CC   C compiler command [cc]

     CFLAGS
          C compiler flags [none]

EXAMPLES

     Compile a script which can be run on other systems with  the
     trace option enabled:

       example% shc -v -r -T -f myscript

BUGS

     The  maximum  size  of the script that could be executed once com�
     piled is limited by the operating system  configuration  parameter
     _SC_ARG_MAX (see sysconf(2))

AUTHOR

     Francisco Rosales <frosal@fi.upm.es>

REPORT BUGS TO

     the author.
分类: Shell 标签:

生成md5密码

2007年1月3日 16hot 没有评论

是使用md5命令,生成md5码,然后截取指定位数作为密码。用于用户密码,不如系统用户,mysql用户等。

#! /bin/sh
# build md5 password
# http://16hot.blog.isyi.com
# 16hot
# 2006-12-31
# $Id: genpw.sh 435 2006-12-31 03:47:55Z 16hot $

ROUND=”YES” ;

SCRIPTNAME=”genpw.sh” ;
MD5=”/sbin/md5″ ;
AWK=”/usr/bin/awk” ;
CUT=”/usr/bin/cut” ;

if [ "$1" = "" ] ; then
echo ;
echo “Syntax: $SCRIPTNAME <key> [length]” ;
echo “Example: ./$SCRIPTNAME my’spassword” ;
echo “Author: 16hot ” ;
echo “Home: http://16hot.blog.isyi.com”;
echo ;
exit ;
else
KEY=”$1″ ;
fi ;

if [ "$2" = "" ] ; then
LEN=”16″ ;
else

test $2 -gt 5 -a $2 -lt 33 2>/dev/null
if [ "$?" != "0" ] ; then
echo ;
echo “The password length must between 6 and 32″ ;
echo “set to default length: 16″ ;
#echo ;
LEN=”16″;
else
LEN=”$2″ ;
fi ;
fi ;

if [ ! -x ${MD5} ] ; then
echo ;
echo “md5 command not found!” ;
echo “Please setup MD5!” ;
echo ;
exit ;
fi ;

if [ ! -x ${AWK} ] ; then
echo ;
echo “awk command not found!” ;
echo “Please install awk and setup AWK” ;
echo ;
exit ;
fi ;

if [ ! -x ${CUT} ] ; then
echo ;
echo “cut command not found!” ;
echo “Please install cut and setup CUT” ;
echo ;
exit ;
fi ;

if [ "${ROUND}" = "YES" ] ; then
NewKey=”${KEY}-genpw-`date +%Y%m%d%H%M%S`” ;
else
NewKey=”${KEY}-genpw” ;
fi ;

#echo ${KEY};
#echo ${NewKey};

## Get OS’s name
OS=”`uname -s`”;

## becuse the diffent OS’s md5 program have diffrent
##
if [ "${OS}" = "FreeBSD" ] ; then
PW=`${MD5} -s “${NewKey}” |  awk -F= ‘{print $2}’ | awk ‘{print $1}’ | ${CUT} -b1-${LEN}` ;
#PW=`${MD5} -s “${NewKey}”` ;
else
echo “Sorry !! only support FreeBSD now.” ;
exit ;
fi ;

echo ;
echo “PW-${LEN}: { ${PW} }” ;
echo ;
echo “Author: 16hot ” ;
echo “Home: http://16hot.blog.isyi.com”;
echo ;
## end script

分类: Shell 标签: ,

升级bash到3.1版本

2006年11月2日 16hot 没有评论

之前一直使用bash-2.0.5版本,今天用portupgrade升级软件。干脆也升级下bash吧。旧版本,登录后提示: su-2.05b# 3.1版本,登录后提示: [root@localhost /root]# 至于3.1版本有些什么新功能,还没有来得及留意。呵呵

不过,对比下,内存消耗却不一样了。

[root@localhost /root]# ps u|grep bash
root 51901 0.0 0.2 2848 1632 p5 S 7:36AM 0:00.01 su (bash)#bash3.1
root 47934 0.0 0.2 2852 1572 p4 I 6:51AM 0:00.02 su (bash)#bash3.1
root 48815 0.0 0.0 1132 0 p3 IW – 0:00.00 su (bash))#bash205
root 17257 0.0 0.1 1136 600 p2 I+ Tue01PM 0:00.53 su (bash)#bash205
root 5933 0.0 0.0 1096 0 p1 IW – 0:00.00 su (bash)#bash205
root 99884 0.0 0.1 1176 592 p0 S+ Tue11AM 0:00.38 su (bash)#bash205
root 58466 0.0 0.2 2848 1632 p5 R+ 8:39AM 0:00.00 su (bash) #bash3.1

如果内存资源不多,并且没有必须bash3.1支持的情况,建议还是用bash2.0.5吧。

分类: BSD/linux, Shell 标签: ,