1、shell脚本
config_file_path=$1
port=$2
sjc=$3
user_name="sdbadmin"
#read -sp "sdbadmin's password: "
passwd="1qaz@WSX123"
#获取当前脚本的执行路径
SCRIPT_PATH=$(cd `dirname $0` ; pwd)
if [ ! -n "${config_file_path}" ];then
echo "主机名或ip的配置文件不能为空,请检查后重新输入!"
exit 1
fi
if [ ! -n "${port}" ];then
echo "待匹配的节点名称不能为空,请检查后重新输入!"
exit 1
fi
if [ -n "${sjc}" ];then
if [[ ! ${sjc} =~ "-" ]];then
echo "时间格式不正确,请输入yyyy-MM-dd格式的日期!"
exit 1
fi
if [[ ${#sjc} -ne 10 ]];then
echo "时间格式不正确,请输入yyyy-MM-dd格式的日期!"
exit 1
fi
fi
sdb_log_path=$(sdblist -l | grep ${port} | awk '{print $10}')
while read line
do
defaultPath=${SCRIPT_PATH}/${line}/${port}
if [ ! -d ${defaultPath} ];then
mkdir -p ${defaultPath}
fi
/bin/expect -f getProductionEnvLog.exp ${user_name} ${passwd} ${line} ${sdb_log_path} ${defaultPath} ${sjc}
done < ${config_file_path}
2、exp脚本
#!/bin/expect -f
#用户名
set user_name [lindex $argv 0]
#密码
set user_passwd [lindex $argv 1]
#ip地址
set host_name [lindex $argv 2]
#目标机器待复制路径
set sdb_log_path [lindex $argv 3]
#当前机器路径
set sdb_save_log [lindex $argv 4]
#匹配指定日期的日志
set log_date [lindex $argv 5]
if {$log_date == ""} {
spawn scp ${user_name}@${host_name}:${sdb_log_path}diaglog/sdbdiag.log ${sdb_save_log}
expect "password*"
send "${user_passwd}\r"
} else {
spawn scp ${user_name}@${host_name}:${sdb_log_path}diaglog/sdbdiag.log.${log_date}* ${sdb_save_log}
expect "password*"
send "${user_passwd}\r"
}
#spawn scp ${user_name}@${host_name}:${sdb_log_path}diaglog/sdbdiag.log.${log_date}* ${sdb_save_log}
#expect "password*"
#send "${user_passwd}\r"
expect eof
#interact
标签:机器,name,user,expect,sdb,path,日志,log From: https://www.cnblogs.com/bzp-cyhf/p/17097916.html