如何查看系统某些脚本或者程序的所有变量,可以使用这种方法:
在bash下运行
env > /root/env.1
程序脚本调用中添加如下脚本
env > /root/env.2
这样就把程序中所有的变量输出到/root/env.2文件下
使用
sdiff -s set.1 set.2 |cut -d">" -f2 > /root/variables_in_use.txt
对比,就ok了。
如何查看系统某些脚本或者程序的所有变量,可以使用这种方法:
在bash下运行
env > /root/env.1
程序脚本调用中添加如下脚本
env > /root/env.2
这样就把程序中所有的变量输出到/root/env.2文件下
使用
sdiff -s set.1 set.2 |cut -d">" -f2 > /root/variables_in_use.txt
对比,就ok了。
SHC:generic shell script compiler
的缩写、简称,shc是一个专业的加密shell脚本的工具,它的作用是把shell脚本转换为一个可执行的二进制文件,这个办法很好的解决了脚本中含有IP、密码等不希望公开的问题.
就可以用shc来加密SHELL。
rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
yum -y install shc
加密:
shc -r -f shell脚本
shc -v -f shell脚本
加完密码之后,会生成三个文件
[root@localhost ~]# file changeyum.sh*
changeyum.sh: Bourne-Again shell script text executable
changeyum.sh.x: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), stripped
changeyum.sh.x.c: ASCII C program text
还可以设定有效期
[root@localhost ~]# shc -e 04/02/2009 -m "Please contact [email protected]" -r -f changeyum.sh
[root@localhost ~]# date
2009年 04月 04日 星期六 17:37:40 CST
[root@localhost ~]# ./changeyum.sh.x 过期了
./changeyum.sh.x: has expired!
Please contact [email protected]
更多内容,请查看
shc --help
那个.c的文件,还可以用gcc编译
gcc -o akin changeyum.sh.x.c
./akin
效果一样
我的机器作为Web开发服务器,每一小时备份一个压缩包出来,每天将昨天的压缩包移动到一个文件夹里面,写的脚本文件一直没解决周末不上班造成的问题。因为man date -d 里面没有详细的 STRING 解释。
今天参考了朽木不可雕的一篇文章,终于找到答案:
date -d “1 days ago” +%Y%m%d ,描述用”2 days ago”,”yesterday”,”tomorrow”.”next-day”,”last-day”,”last-month”,”next- month”,”next-year”也可。
于是我的daily_webbackup.sh这样写:
#!/bin/bash
basedir=/backup/webbackup/
prefix=web
suffix=$(date +%Y%m%d -d “yesterday”)
suffix1=$(date +%Y%m%d -d “2 days ago”)
suffix2=$(date +%Y%m%d -d “3 days ago”)
destdir=$basedir$prefix$suffix
destdir1=$basedir$prefix$suffix1
destdir2=$basedir$prefix$suffix2
if [ -e $destdir*.tar.gz ]; then
if [ ! -e $destdir ]; then
mkdir $destdir
fi
mv $destdir*.tar.gz $destdir/
elif [ -e $destdir1*.tar.gz ]; then
if [ ! -e $destdir1 ]; then
mkdir $destdir1
fi
mv $destdir1*.tar.gz $destdir/
elif [ -e $destdir2*.tar.gz ]; then
if [ ! -e $destdir2 ]; then
mkdir $destdir2
fi
mv $destdir2*.tar.gz $destdir/
fi
exit 0
由于是在/etc/cron.daily/里面运行,脚本没有 echo 任何信息。