
我有一個腳本可以登入遠端伺服器。
紀錄:
我的腳本:
#!/bin/bash
S1=$(ssh -t selvam-odc-shell1 "users | wc -w ")
S2=$(ssh -t selvam-odc-shell2 "users | wc -w ")
S3=$(ssh -t selvam-odc-shell3 "users | wc -w ")
if [ "$S1" -le 100 ];
then
ssh -t selvam-odc-shell1 " bash"
if [ "$S2" -le 100 ];
then
ssh -t selvam-odc-shell2 "bash"
elif [ "$S3" -le 100 ];
then
ssh -t selvam-odc-shell3 "bash"
else
echo " Shell has been more than 100 users.Please try again later
fi
但是o/p
[user@selvam-odc-sunray2: ~]#./shell.sh
Connection to selvam-odc-shell1 closed.
Connection to selvam-odc-shell2 closed.
Connection to selvam-odc-shell3 closed.
: integer expression expected60
: integer expression expected 29
請幫我解決這個問題。
謝謝MM塞爾瓦姆
答案1
ssh 指令不僅添加數字,還添加換行符。這意味著您的變數具有以下內容:“1\n”,它不是整數。
刪除引號: S1=$(ssh -t selvam-odc-shell1 users | wc -w )