常用Shell
程序员文章站
2022-03-04 16:16:09
...
一、拷贝文件到其它机器,自动输入密码(需安装expect模块)
1、scp_hosts.sh
#!/bin/bash
scpTo() {
./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
set node [lindex $argv 0] # 获取第0个参数
spawn scp /etc/hosts [email protected]$node:/etc
expect {
"(yes/no)" {send "yes\r"}
"password:" {send "123456\r"}
}
expect eof
二、json格式化(需安装jq模块)
#!/bin/sh
path=$1 # 入参 一行的json字符串文本路径
if [ -z $path ]; then
echo "path is null"
else
cat $path | jq . > json_format.txt
fi