在请求之间排队的Bash脚本?

时间:2018-11-21 08:35:48

标签: linux bash server

我想在服务器发出请求时运行bash脚本。 我的代码是当请求来自request1时,请使用ip1重新启动服务器。 为了测试,我为样本请求写了“ a”。

当同时有2个请求时,我想要一个脚本,第一个请求先运行,然后第二个请求运行!

有可能吗?

这是我的代码:

#!/bin/bash
a=request
arr1=(request1 request2 request3)
arr2=(ip1 ip2 ip3)

user=user
password=123456
if [ $a = ${arr1[0]} ]; then
    b=${arr2[0]}
    echo $b
elif [ $a = ${arr1[1]} ]; then
    b=${arr2[1]}
    echo $b
elif [ $a = ${arr1[2]} ]; then
    b=${arr2[2]}
    echo $b
fi

id=$b
expect2=$(expect -c "
spawn ssh $user@$id
expect \"continue connecting (yes/no)?\"
send \"yes\r\"
expect \"password:\"
send \"$password\r\"
expect -exact \":~$\"
send \"sudo shutdown -r now\r\"
expect \"password:\"
send \"$password\r\"
expect -exact \":~$\"
")
echo "$expect2"

0 个答案:

没有答案