1

i am trying to make a zenity shell menu to manage 50+ servers and want to add multiple customized functions. e.g:- when server goes down i want to ssh in it, then check load,free -m, last 10 mins apache/nginx logs,exim logs,mysql slow query logs and many more. i have scripts for all these needs.

those servers have my ssh key so theres no problm in doing ssh.

i am successfully logging in servers, but the thing is when i get into server via ssh, the script ends and after i exit for server, i comes on my local machine's terminal with no script, then i have to again run script to get server menu. Please tell me how can i stay in loop i mean how to stay in server menu , then ssh into any server, and when i exit from server come back to server menu. please help . i want to customize it more.

=========== its short script to give you guys idea. my origial script have all servers======

#!/bin/bash
dialog --menu "select" 40 40 5 1 server.hades 2 server.fire 3 server.geb 4 server.isis 5 exit 2> /tmp/a
choice=`cat /tmp/a`
if [ $choice -eq 1 ]
then
ssh 1.2.3.4
fi
if [ $choice -eq 2 ]
then
ssh 2.3.4.5
fi
if [ $choice -eq 3 ]
then
ssh 2.3.3.5
fi
if [ $choice -eq 4 ]
then
ssh 8.3.4.8
fi
if [ $choice -eq 5 ]
then
echo "BIE BIE"
fi
0

It looks like you want to run the script in some loop, but you miss the loop. The simples modification will probably be this modification:

[... the rest of choices ...]
if [ $choice -eq 5 ]
then
  echo "BYE BYE"
  exit
fi
exec $0

This will exit if you will choose the last option (5), but otherwise reexecute the script itself.

Or just add a cycle:

while true;
do
  dialog --menu "select" 40 40 5 1 server.hades 2 server.fire 3 server.geb 4 server.isis 5 exit 2> /tmp/a
  choice=`cat /tmp/a`
  if [ $choice -eq 2 ]
  then
    ssh 192.168.187.*
  fi
  [... the rest of choices ...]
  if [ $choice -eq 5 ]
  then
    echo "BIE BIE"
    break
  fi
done

"while" code worked for me. thankyou.

  • it didnt work, ended up with error. Please help. [root@server ~]# sh sshautologin ### now menu comes #### Last login: Tue May 9 01:25:13 2017 from 192.168.187.129 [root@server ~]# [root@server ~]# [root@server ~]# ip a | grep -w inet inet 127.0.0.1/8 scope host lo inet 192.168.187.139/24 brd 192.168.187.255 scope global dynamic eno16777736 inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0 [root@server ~]# exit logout Connection to 192.168.187.139 closed. sshautologin: line 13: exec: sshautologin: not found [root@centeralized Desktop]# – Navdeep.D2 May 8 '17 at 19:59
  • How do you start the script? – Jakuje May 10 '17 at 10:12
  • sh script on exiting from remote server its again logging in server via ssh, i think it is because of i am saving the dialog choice in file. please tell me how to get back to menu – Navdeep.D2 May 10 '17 at 19:11
  • while true; do dialog --menu "select" 40 40 5 1 server.hades 2 server.fire 3 server.geb 4 server.isis 5 exit 2> /tmp/a choice=cat /tmp/a` if [ $choice -eq 2 ] then ssh ..*.* fi if [ $choice -eq 5 ] then echo "BIE BIE" break fi done` its working with "while". thankyou – Navdeep.D2 May 10 '17 at 19:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.