#!/bin/bash

date=$1

if [ $2 == 5g ]; then
  # 修改gpload配置文件
  sed -i 's/\/data\/terminal\/distinct\/g5_terminal_[0-9]\{8\}.csv/\/data\/terminal\/distinct\/g5_terminal_'${date}'.csv/' /data/terminal/gpload/g5.yml
  yml=g5.yml
elif [ $2 == volte ]; then
  # 修改gpload配置文件
  sed -i 's/\/data\/terminal\/distinct\/volte_terminal_[0-9]\{8\}.csv/\/data\/terminal\/distinct\/volte_terminal_'${date}'.csv/' /data/terminal/gpload/volte.yml
  yml=volte.yml
fi

# 由于gpload需要输入密码，这里需要使用expect执行
password=Richr00t#
bin_path=$GPHOME_LOADERS

expect -c "
set timeout 300
spawn ${bin_path}/bin/gpload -f /data/terminal/gpload/${yml}
expect {
\"connecting (yes/no)?\" { send \"yes\n\";exp_continue }
\"Password:\" { send \"${password}\n\"; exp_continue}
timeout { puts \"超时\" exit 2}
}
"