shell各类脚本
#批量修改当前目录下的文件扩展名,将.doc改为.txt1. # vim ../renfilex.sh
2. #!/bin/bash
3. for FILE in "$1"
4. do
5. mv $FILE ${FILE%$1}"$2"
6. done
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
编写sumx.sh脚本,从键盘读入一个正整数x,求从1到x的和
1. # vim sumx.sh
2. #!/bin/bash
3. read -p "请输入一个正整数:" x
4. x=${x:-1}
5. i=1; SUM=0
6. while [ $i -le $x ]
7. do
8. let SUM+=i
9. let i++
10. done
11. echo "从1到$x的总和是:$SUM"
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
99乘法表
1 #!/bin/bash
2 for((i=1;i /dev/null
if [ $? -eq 0 ];then
echo $ip is online
else
echo $ip is not online
fi
#
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
屏幕输入3个ip地址,保存到ipgrp数组里,并在屏幕输出第二个IP
#!/bin/bash
read -p "qing shuru yige ipdizhi: " ipa
read -p "qing shuru yige ipdizhi: " ipb
read -p "qing shuru yige ipdizhi: " ipc
ipgrp=($ipa $ipb $ipc)
echo ${ipgrp}
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++expect
从ftp服务器上下载文件到本机
#!/usr/bin/expect
set ip "localhost"
set username "ftp"
set password ""
set path [ lindex $argv 0 ]
set file [ lindex $argv 1 ]
spawn ftp $ip
expect "Name"
send "$username\r"
expect "Password"
send "$password\r"
expect "ftp>"
send "cd $path\r"
expect "ftp>"
send "get $file\r"
expect "ftp>"
send "bye\r"
:wq
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
远程修改用户密码脚本
#!/bin/bash
oldpass=123456
newpass=654321
for ip in $(cat /root/ip.txt)
do
expect
页:
[1]