存档

文章标签 ‘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 标签:

Enable core dump in Linux and FreeBSD(转)

2010年4月26日 16hot 没有评论

Just a note.

You can enable core dump by:

[bash] edit /etc/profile

ulimit -c unlimited

[csh/tcsh] edit /etc/csh.cshrc

limit coredumpsize unlimited

You can disable core dump by:

[bash] edit /etc/profile

ulimit -c 0

[csh/tcsh] edit /etc/csh.cshrc

limit coredumpsize 0

On FreeBSD, you also need to check the setting of kern.coredump:

# sysctl -a |grep kern.coredump
kern.coredump: 0
# sysctl kern.coredump=1
kern.coredump: 0 -> 1
# sysctl -a | grep kern.coredump
kern.coredump: 1

You can enforce this setting in /etc/sysctl.conf

[2008/01/01] Thanks for the complement from gslin, kern.sugid_coredump controls the core dump for setuid/setgid process in FreeBSD.

分类: BSD/linux, 转载 标签: , ,

升级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 标签: ,