#!/bin/bash
###批量重命名图片名字的脚本
count=1;
for img in *.jpg *.png *.jpeg
do
new=image$count.${img##*.}
mv "$img" "$new"
if [ $? -eq 0 ] ;then
echo "file $img to $new"
let count++
fi
done
cat /var/script/tab_bak2.sh
#!/bin/bash
backupDir=/backup/mysql
ftpUser=femar4t43a
ftpPWD='d:8G2l'
file=`ls -t /backup/mysql|grep '[0-9]\{11,12\}' |sed -n '20,$p'`
for i in $file;do
rm -rf /backup/mysql/$i
done
DATE=`date +%Y%m%d%H%M`
MYSQL='mysql -uroot -p'1Iw8wdg''
IP='8.8.8.8'
cd /backup/mysql && mkdir -p $DATE && cd $DATE
for table in `$MYSQL -e "use femart; show tables" |sed '1d'` ; do
/usr/local/mysql/bin/mysqldump -uroot -p'1Ig' femart $table |gzip > femart.$table.sql.gz
echo "`date +%Y%m%d%H%M` mysqlback stop,start compress!" >>"$backupDir"/`date +%Y%m%d`.log
date=`date +%Y%m%d-%H%M`
done
tar cvf mysql-$IP-$DATE.tar *.gz
echo "`date +%Y%m%d%H%M` mysqlback end!" >>"$backupDir"/`date +%Y%m%d`.log
rm -rf *.sql.gz
date0=`date +%Y%m%d`
cd $backupDir/$DATE
/usr/bin/ftp -n<
open 192.168.0.124 60017
user $ftpUser $ftpPWD
bin
#passive
mkdir $date0
cd $date0
put mysql-$IP-$DATE.tar
bye
quit
EOF
ftpUser2=femar
ftpPWD2='d@8G2l'
date0=`date +%Y%m%d`
cd $backupDir/$DATE
/usr/bin/ftp -n<
open 192.168.0.115 21
user $ftpUser2 $ftpPWD2
bin
#passive
mkdir $date0
cd $date0
put mysql-$IP-$DATE.tar
bye
EOF
[root@oracle ~]# chmod 711 case_break.sh
[root@oracle ~]# ./case_break.sh
Enter any number [1..5]:1
great you entered a number between 1 and 5
Enter any number [1..5]:2
great you entered a number between 1 and 5
Enter any number [1..5]:3
great you entered a number between 1 and 5
Enter any number [1..5]:4
great you entered a number between 1 and 5
Enter any number [1..5]:5
great you entered a number between 1 and 5
Enter any number [1..5]:6
Wrong number..bye
[root@oracle ~]# cat ./case_break.sh
#!/bin/bash
while :
do
echo -n "Enter any number [1..5]:"
read ANS
case $ANS in
1|2|3|4|5) echo "great you entered a number between 1 and 5"
;;
*) echo "Wrong number..bye"
break
;;
esac
done
awk '{ $1=null ; print }' rename.sh 删除一个文件(rename.sh) 里的第一列
sed -e '4,/^$/!d;/^$/d' 是什么意思
4,/^$/!d 这是表示把 第4行到下个空行之间的所有行都保留,其他行都删除
/^$/d 表示删除空行
所以两个命令连起来 (通过 ; )的效果是,保留从第四行开始的非空行,其他都删掉。
sed "/But/s/is/are/g" sedtest.txt
对那些包含But字符串的行,把is替换成are
sed "s/^$/(&)/" sedtest.txt
给所有空行增加一对()
sed "s/is/(&)/g" sedtest.txt
给所有is字符串外增加()
sed "s/.*/(&)/" sedtest.txt
给所有行增加一对()
sed "/is/s/.*/(&)/" sedtest.txt
给所有包含is字符串的行增加一对()
sed -e '3,5 a 4444444' passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
4444444
adm:x:3:4:adm:/var/adm:/sbin/nologin
4444444
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
4444444
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
批量杀mysql 的线程
mysql -uroot -p'password' -e "show full processlist" |awk '{ print $1 }' |sed -n '5,190p' |sed 's/^/mysql -uroot -p"password" -e " kill /g' |sed 's/$/ ; "/g' |sh -x
vi fangmo.txt
13213
root@ct458-server:/home/ct458/databasebackup# more fangmo.txt |sed -e 's/./&\n/g'
1
3
2
1
3
cat passwd |sed -e 's/../&\n/g' |awk '{ printf "%s",$0 }'
root:x:0:0:root:/root:/bin/bashbin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:daemon:/sbin:/sbin/nologinadm:x:3:4:adm:/var/adm:/sbin/nologinlp:x:4:7:lp:/var/spool/lpd:/sbin/nologinsync:x:5:0:sync:/sbin:/bin/syncshutdown:x:6:0:shutdown:/sbin:/sbin/shutdownhalt:x:7:0:halt:/sbin:/sbin/haltmail:x:8:12:mail:/var/spool/mail:/sbin/nologinnews:x:9:13:news:/etc/news:uuc
把多行变成一行。
linux对^M换行符的处理2011-11-23 17:00:06
我来说两句 [字体:
]
经常在WINDOWS编辑的文件传送到LINUX在每行末尾都有一个^M符号,这个会导致shell脚本运行错误。
这是因为DOS下的编辑器和编辑器对文件行末的回车符处理不一致
有两种方法可以将^M去掉
1.我们可以在VI编辑器里把^M进行删除:
将VI切换至命令行模式,输入(注意输入这个^M,这个不是shift+^再加上M,应该是ctrl+v加上ctrl+m)
:%s/^M//g --该命令copy无效,注意^M的输入
在vi命令行模式执行上面的命令,可以将所有行末的^M去掉
2.可以使用2unix命令
dos2unix filename
本文出自 “richard的笔记” 博客
find . -maxdepth 3 -type f -name
"configure.php" |sed "s/\(.*\)/\1 \1/" |sed
"s/configure.php/configure.php_bak/2" |sed "s/^/cp -f /g"
find . -type f -name ecpss.gif |sed "s/\(.*\)/\1 \1_bak/" |sed 's#^# mv #g' |sh -x
sed -i "s/oldString/newString/g" `grep oldString -rl /path`
#!/bin/bash
i=1
while [ $i -lt 100 ]
do
echo $i>> newfile
let i=i+2
done
[13:12:22] PWD => ~
3># cat newfile
1
3
5
7
9
11
13
15
17
#!/bin/bash
while read site
do
echo "server" >> i1i2blog.conf
echo { >>i1i2blog.conf
echo -e "\tlisten 80" >> i1i2blog.conf
echo -e "\tserver_name $site " >> i1i2blog.conf
echo -e "\tindex index.html index.htm index.php default.htm default.html default.php" >> i1i2blog.conf
echo -e "\troot /data0/htdocs/" >> i1i2blog.conf
echo -e "\tinclude rewrite.conf" >> i1i2blog.conf
echo } >> i1i2blog.conf
done <"list.txt"
cat dd.sh
#!/bin/bash
while read site
do
echo " root /data0/htdocs/;" >> i1i2blog.conf;
echo
done <./list.txt
14># cat ping.sh
#!/bin/bash
for n in `seq 254` ; do
host=192.168.100.$n
ping -c 3 $host & > /dev/null
if [ $? = 0 ] ; then
echo "$host is UP"
echo "$host" >> /tmp/alive
else
echo "$host is DOWN"
fi
done
yum list updates |awk '{ print $1 }' |grep "86$" |awk -F "." '{ print $1 }' |sed 's/.*/&* /g' |awk '{ printf "%s" , $0 }' |sed 's/^/yum -y install --skip-broken /g' |sh -x
阅读(1365) | 评论(0) | 转发(0) |