shell替换文件中的文件路径脚本分享
用法
参数1、写有需要替换路径记录的文本,格式:老路径 老名称 新路径 新名称
参数2、需要替换的文件的目录
参数3、需要替换的文件的类型
#!/bin/shfunction _replace(){
basepath=$0
> $basepath.log
i=1
while read line
do
echo "start===================================================================================" >> $basepath.log
oldpath=`echo $line|awk '{print $1$2}'|sed 's/^///g'`
newpath=`echo $line|awk '{print $3$4}'|sed 's/^///g'`
echo $oldpath >> $basepath.log
echo $newpath >> $basepath.log
if [ "$oldpath" != "" ] && [ "$newpath" != "" ];then
refiles=`grep $oldpath -irl --include="*.$3" $2`
for refile in $refiles
do
sed -i 's#'$oldpath'#'$newpath'#ig' $refile
echo $refile >> $basepath.log
done
fi
echo "end=====================================================================================" >> $basepath.log
echo "=">> $basepath.log
echo $i >> $basepath.log
echo "=">> $basepath.log
i=$(($i+1))
done < $1
}if [ "$1" != "" ] || [ "$2" != "" ] || [ "$3" != "" ];then
_replace $1 $2 $3
else
echo "use like this:$basepath file filepath type"
fi
shell中删除文件中重复行的方法
Linux下文本处理工具很丰富很强大,例如这样一个文件:catlogwww.gimoo.net192.168.1.1www.gimoo.net192.168.1.1www.gimoo.net192.168.1.2ffffffffffffffffffffffffffffffffffffeeeeeeeeeeee
centos中mysql备份数据库脚本分享
#!/bin/bash#backupmysqldataDBDIR=/data/mysqlBACKDIR=/data/bak/mysqlTIME=`date-d"today"+%F`DB=$(ls-p$DBDIR|grep/|tr-d/|grep-Ev'information_schema|performance_schema|mysql|test')/etc/init.d/mysqldstopif
shell脚本转发80端口数据包给Node.js服务器
注意:千万不要图省事直接使用ROOT用户运行Node.js服务!这将带来无法预计的安全问题!但是使用80端口作为HTTP默认端口这一习惯是从MS时代就延续至今