
Eu tenho um script para fazer login no servidor remoto. Mas tentei executar o script e ocorreu algum erro.
Histórico:
Meu roteiro:
#!/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
Mas 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
Por favor, me ajude a resolver este problema.
Obrigado MM SELVAM
Responder1
O comando ssh não apenas adiciona o número, mas também adiciona uma nova linha. O que significa que suas variáveis têm um conteúdo como este: "1\n" que não é um número inteiro.
Remova as aspas: S1=$(ssh -t selvam-odc-shell1 users | wc -w )