测试常用的shell脚本

一:手工造文件数据的脚本
#!/bin/sh
counter=0

while [ 1 = 1 ]
do
DATE=`date +%Y%m%d%H%M%S`

#I2000 LOG
cp /home/test/i2000/20120523093511-operation-log-3rdQuery.txt  /lun_logserver/logaudit/i2000/operation/operation_$DATE.txt
cp /home/test/i2000/20120523093504-security-log-3rdQuery.txt  /lun_logserver/logaudit/i2000/security/security_$DATE.txt
cp /home/test/i2000/20120623093505-system-log-3rdQuery.txt  /lun_logserver/logaudit/i2000/system/system_$DATE.txt

#WINDOWS LOG
cp /home/test/windows/os_201207301022.log /lun_logserver/logaudit/os/syslog/windows/X66431G/os_$DATE.log

#linux log
#cp /home/test/syslog/os_201207301019.log /lun_logserver/logaudit/os/syslog/syslog-ng/lcap229/os_$DATE.log
#cp /home/test/syslog/os_201207301019.log /lun_logserver/logaudit/os/syslog/syslog-ng/master/os_$DATE.log
cp /home/test/syslog/os_201207301019.log /lun_logserver/logaudit/os/syslog/syslog-ng/slave/os_$DATE.log

#uoasyslog
cp /home/test/uoasyslog/security/BMP1/log_201205230950.log /lun_logserver/logaudit/syslog_uoa/security/BMP1/os_$DATE.log
cp /home/test/uoasyslog/operator/RPT1/log_201205281023.log /lun_logserver/logaudit/syslog_uoa/operator/RPT1/os_$DATE.log
cp /home/test/uoasyslog/run/atae29/log_201205270257.log    /lun_logserver/logaudit/syslog_uoa/run/atae29/os_$DATE.log
cp /home/test/uoasyslog/run/BMP1/log_201205230950.log      /lun_logserver/logaudit/syslog_uoa/run/BMP1/os_$DATE.log

#oracle log
cp /home/test/oracle/logaudit_ora_23921_3.xml /lun_logserver/logaudit/oracle/11g/security/oracle_$DATE.xml
cp /home/test/oracle/logaudit_ora_23628_1.xml /lun_logserver/logaudit/oracle/11g/security/oracle_$DATE.xml.snap

#network
cp /home/test/network/network_all_types.log /lun_logserver/logaudit/os/syslog/network/linux/network_$DATE.log

counter=`expr $counter + 1`

echo "-------$counter times------" >> /home/test/counter.txt
sleep 12
done

或者:
#!/bin/ksh
rm -rf sdp

mkdir -p sdp/mdcc/user/usera
mkdir -p sdp/mdcc/user/userb
mkdir -p sdp/mdcc/user/userc
mkdir -p sdp/mdcc/user/userd

./copyfile  file.xml  usersdp_mdcc_201010010 sdp/mdcc/user/usera   
./copyfile  file.xml  usersdp_mdcc_201010010 sdp/mdcc/user/userb
./copyfile  file.xml  usersdp_mdcc_201010010 sdp/mdcc/user/userc
./copyfile  file.xml  usersdp_mdcc_201010010 sdp/mdcc/user/userd

copyfile:

#!/bin/ksh

NUMBER=10
A=0
while [ $A -lt $NUMBER ]
do
#echo $A
cat $1 > $2$A.log
mv  $2$A.log  $3 
A=`expr $A + 1`
done

exit 0

二:查看内存占用情况的脚本
#!/bin/sh
while [ 1=1 ]
do
pt=`date`
pst=`top -n 1 -p 32526|grep logserve | awk '{print $9, $10}'`
echo $pst $pt >> memory.txt
sleep 1
done

三:修改名字的脚本
#!/bin/sh
#查找路径
path=/lun_lcap/lcstore
#文件名匹配规则
regex1=[0-9]+.log
regex2=[0-9]+.txt
#安装路径
installpath=/home/lcap/lcpp/shell
scriptname=rename_task.sh

#改名
rename_file()
{
#
list=`find $path -mmin +1 -regex "${path}/.*/${regex1}\|${path}/.*/${regex2}"`
for l in ${list[@]}
do
#l=/lun_lcap/lcstore/sag/sag/cdr/statistic/172.19.123.24/201201010.log
component=`echo -n $l|awk -F/ '{print $4}'`
module=`echo -n $l|awk -F/ '{print $5}'`
log=`echo -n $l|awk -F/ '{print $6}'`
ip=`echo -n $l|awk -F/ '{id=NF - 1; print $id}'`
fn=`echo -n $l|awk -F/ '{print $NF}'`

p=${l/${fn}//}

fn=${fn/%log/txt}

#
mv $l ${p}/${component}_${module}_${log}_${ip}_${fn}
done
}

#setup
addcrontab()
{
crontab -l 2>/dev/null | grep -v '#' > ${installpath}/cron.cfg
cat ${installpath}/cron.cfg |grep "${installpath}/${scriptname}"
if [ $? -eq 0 ]; then
rm ${installpath}/cron.cfg
return 0
fi
echo "*/30 * * * * ${installpath}/${scriptname}" >> ${installpath}/cron.cfg
crontab ${installpath}/cron.cfg
rm ${installpath}/cron.cfg
}

delcrontab()
{
    crontab -l 2>/dev/null | grep -v '#' | grep -v "${installpath}/${scriptname}" > ${installpath}/cron.cfg
    crontab ${installpath}/cron.cfg
    rm -f ${installpath}/cron.cfg
}


#安装
setup()
{
#注册到系统的定时任务中去
addcrontab
}
#卸载
unsetup()
{
delcrontab
}

#如果指定了setup/unsetup就进行安装
#否则执行功能参数
if [ "X$1" == "Xsetup" ]; then
setup
elif [ "X$1" == "Xunsetup" ]; then
unsetup
else
rename_file
fi

四:启动FTP进程的脚本
#!/bin/ksh

cp /etc/xinetd.d/vsftpd /etc/xinetd.d/vsftpd_tmp

cat /etc/xinetd.d/vsftpd_tmp | awk '{if ($1=="disable"){print "\tdisable = no"}else{print $0}}' > /etc/xinetd.d/vsftpd

rm /etc/xinetd.d/vsftpd_tmp

/etc/init.d/xinetd restart

exit 0

你可能感兴趣的:(shell脚本)