LINUX免密登录SSH下的操作之SHELL
姑且把LINUX免密登录SSH下的操作之SHELL叫xshell吧,简单粗暴的方式先用起来,
放在~/bin/下的xshell脚本源码如下:
#!/bin/sh #author :zhangmingwei 20200324 #cmd e.g: xshell mkdir -p ~/{app,tools,log} ; xshell date #echo $* #echo $@ #echo $# hos1=$(hostname) argcnt=$# if [ $argcnt -lt 1 ];then echo "your input's args is less than 1,please try input agin!" exit fi hts="01 02 03" pre=hadoop user=$pre xcmd="$@" for h in $hts do hos=$pre$h echo "$hos" ssh ${user}@$hos " $xcmd " #if [ "$hos"x = "$hos1"x ];then ssh "$xcmd" else ssh ${user}@$hos " $xcmd " fi #换成本机shell执行有bug,所以还是用ssh #echo $h done
然后添加操作权限:chmod +x ~/bin/xshell
调用:
xshell date
xshell mkdir ~/{app,tools,data} #批量创建家目录下的app tools data目录

浙公网安备 33010602011771号