1、定义关联数组 磁盘分区(键) 利用率(值);键值对先存放的后取出

file=/app/disk
if [ ! -e $file ];then
        file=`touch /app/disk`
fi
echo $file
df | grep "/dev/sd" >> $file
while read line ;do
        index=`echo "$line" | cut -d " "  -f1`
        value=`echo "$line" | sed -r 's/.* ([0-9]+)%.*/\1/'`
        declare -A dUse
        dUse["$index"]="$value"
done < ${file}

echo ${dUse[*]}

2、将下图所示,实现转置矩阵matrix.sh 1 2 3 1 4 7 4 5 6 ===> 2 5 8 7 8 9 3 6 9

juzheng[01]=2
juzheng[02]=3
juzheng[10]=4
juzheng[11]=5
juzheng[12]=6
juzheng[20]=7
juzheng[21]=8
juzheng[22]=9
display() {
        for((i=0;i<size;i++));do
                for((j=0;j<size;j++));do
                        echo -n "${juzheng[${i}${j}]}  "
                done
        echo 
done
}
#display before matrix
echo "display before matrix"
display
#matrix
for((i=0;i<size;i++));do
        for((j=i+1;j<size;j++));do
                temp=${juzheng[$i$j]}
                juzheng[$i$j]=${juzheng[$j$i]}
                juzheng[$j$i]=$temp
        done
done
#after matrix
echo "after matrix"
display

3、使用expect 工具让客户端自动登录ssh服务的远程主机并创建haha用户和重置密码

ip=$1
user=$2
passwd=$3
echo "-----"
echo $passwd
expect <<EOF
set timeout 10
#auto login
spawn ssh $user@$ip
expect {
        "yes/no"{ send "yes\n";exp_continue }
        "password" { send "${passwd}\n" }
}
#create user and change password after login
expect "]#" { send "useradd haha\n" }
expect "]#" { send "echo yangguang | passwd --stdin haha\n" }
#logout 
expect "]#" { send "exit\n" }
#quit expect
expect eof
EOF