常用Shell

一、拷贝文件到其它机器,自动输入密码(需安装expect模块)
1、scp_hosts.sh

#!/bin/bashscpTo() { ./scp_hosts.exp $1 }scpTo 192.168.30.164 scpTo 192.168.30.165 scpTo 192.168.30.166

2、scp_hosts.exp
#!/usr/bin/expect# 获取第0个参数 set node [lindex $argv 0]spawn scp /etc/hosts root@$node:/etc expect { "(yes/no)" {send "yes\r"} "password:" {send "123456\r"} } expect eof

二、json格式化(需安装jq模块)
#!/bin/shpath=$1# 入参 一行的json字符串文本路径if [ -z $path ]; then echo "path is null" else cat $path | jq . > json_format.txt fi

【常用Shell】

    推荐阅读