一个有用的shell脚本

时间:2023-03-08 21:58:58
#!/bin/bash

#if [ $1 -eq null ]; then
# echo "please input params1!"
# exit
#fi #if [ $2 -eq null ]; then
# echo "please input params2!"
# exit
#fi # type , $ { scp, ssh }, src $, dst $
user=hadoop if [ "$3" != "" -a "$1" != "scp" ] ; then
user=$
fi if [ "$4" != "" ] ; then
iplist=$
else
iplist=`cat /home/hadoop/gitclone/opshell/hadoop/machine.conf`
fi for ip in $iplist;do
echo "-----ops $ip -------------"
if [ "$1" == "scp" ] ; then
scp -r $ $user@$ip:$
elif [ "$1" == "ssh" ] ; then
ssh $user@$ip "mkdir ~/.ssh | touch ~/.ssh/authorized_keys"
cat ~/.ssh/id_rsa.pub | ssh $user@$ip "cat >> ~/.ssh/authorized_keys"
ssh $user@$ip "chmod 700 ~/.ssh"
elif [ "$1" == "cmd" ] ; then
ssh $user@$ip "$2"
fi
done