Stopping and Starting Multiple services on multiple servers in Linux on same network and doing it by sitting on a single server? [closed]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












1















Take for example i have 4 servers A,B,C,D. All are on same network and all have same services running like Apache, Tomcat etc and when patching is required to be done on these servers i need to stop, Start these services. Right now i am manually going into all the servers and doing the same. I know SSH can be done here but i am looking for a script which i when click gives me options:



Which server i want to go in.
Once i get in for example server C. Script should automatically ask which service u want to Stop? I am hoping we can declare these services with path in the script.
Once stopped it should display a message that this particular service is stopped.
It should not stop here, it needs to go on as i might or i have to stop other services on other server..
And then there should be something to start them.
Need to do this sitting on a single server. In my prod. environment i have 25 servers it is a pain for me to jump in every server or even doing SSH all the time. I know there can be script written and might be a long one.



PS: I cannot use and install Ansible.










share|improve this question















closed as too broad by Mr Shunz, mosvy, Jeff Schaller, Christopher, A.B Jan 10 at 21:40


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


















  • Ansible is kind of built for situations like this. Any major reasons for not being able to use it?

    – Haxiel
    Jan 10 at 10:08











  • Possible duplicate of Is there a way to administrate multiple computers at the same time?

    – Christopher
    Jan 10 at 13:38















1















Take for example i have 4 servers A,B,C,D. All are on same network and all have same services running like Apache, Tomcat etc and when patching is required to be done on these servers i need to stop, Start these services. Right now i am manually going into all the servers and doing the same. I know SSH can be done here but i am looking for a script which i when click gives me options:



Which server i want to go in.
Once i get in for example server C. Script should automatically ask which service u want to Stop? I am hoping we can declare these services with path in the script.
Once stopped it should display a message that this particular service is stopped.
It should not stop here, it needs to go on as i might or i have to stop other services on other server..
And then there should be something to start them.
Need to do this sitting on a single server. In my prod. environment i have 25 servers it is a pain for me to jump in every server or even doing SSH all the time. I know there can be script written and might be a long one.



PS: I cannot use and install Ansible.










share|improve this question















closed as too broad by Mr Shunz, mosvy, Jeff Schaller, Christopher, A.B Jan 10 at 21:40


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


















  • Ansible is kind of built for situations like this. Any major reasons for not being able to use it?

    – Haxiel
    Jan 10 at 10:08











  • Possible duplicate of Is there a way to administrate multiple computers at the same time?

    – Christopher
    Jan 10 at 13:38













1












1








1








Take for example i have 4 servers A,B,C,D. All are on same network and all have same services running like Apache, Tomcat etc and when patching is required to be done on these servers i need to stop, Start these services. Right now i am manually going into all the servers and doing the same. I know SSH can be done here but i am looking for a script which i when click gives me options:



Which server i want to go in.
Once i get in for example server C. Script should automatically ask which service u want to Stop? I am hoping we can declare these services with path in the script.
Once stopped it should display a message that this particular service is stopped.
It should not stop here, it needs to go on as i might or i have to stop other services on other server..
And then there should be something to start them.
Need to do this sitting on a single server. In my prod. environment i have 25 servers it is a pain for me to jump in every server or even doing SSH all the time. I know there can be script written and might be a long one.



PS: I cannot use and install Ansible.










share|improve this question
















Take for example i have 4 servers A,B,C,D. All are on same network and all have same services running like Apache, Tomcat etc and when patching is required to be done on these servers i need to stop, Start these services. Right now i am manually going into all the servers and doing the same. I know SSH can be done here but i am looking for a script which i when click gives me options:



Which server i want to go in.
Once i get in for example server C. Script should automatically ask which service u want to Stop? I am hoping we can declare these services with path in the script.
Once stopped it should display a message that this particular service is stopped.
It should not stop here, it needs to go on as i might or i have to stop other services on other server..
And then there should be something to start them.
Need to do this sitting on a single server. In my prod. environment i have 25 servers it is a pain for me to jump in every server or even doing SSH all the time. I know there can be script written and might be a long one.



PS: I cannot use and install Ansible.







linux shell-script ssh






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 10 at 19:01









Rui F Ribeiro

39.6k1479132




39.6k1479132










asked Jan 9 at 16:55









Sidharath SainiSidharath Saini

61




61




closed as too broad by Mr Shunz, mosvy, Jeff Schaller, Christopher, A.B Jan 10 at 21:40


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









closed as too broad by Mr Shunz, mosvy, Jeff Schaller, Christopher, A.B Jan 10 at 21:40


Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • Ansible is kind of built for situations like this. Any major reasons for not being able to use it?

    – Haxiel
    Jan 10 at 10:08











  • Possible duplicate of Is there a way to administrate multiple computers at the same time?

    – Christopher
    Jan 10 at 13:38

















  • Ansible is kind of built for situations like this. Any major reasons for not being able to use it?

    – Haxiel
    Jan 10 at 10:08











  • Possible duplicate of Is there a way to administrate multiple computers at the same time?

    – Christopher
    Jan 10 at 13:38
















Ansible is kind of built for situations like this. Any major reasons for not being able to use it?

– Haxiel
Jan 10 at 10:08





Ansible is kind of built for situations like this. Any major reasons for not being able to use it?

– Haxiel
Jan 10 at 10:08













Possible duplicate of Is there a way to administrate multiple computers at the same time?

– Christopher
Jan 10 at 13:38





Possible duplicate of Is there a way to administrate multiple computers at the same time?

– Christopher
Jan 10 at 13:38










1 Answer
1






active

oldest

votes


















1














This might give you a starting point. Note there is no sanity-checking done here:



#!/usr/local/bin/bash
# example invocations:
# script.sh - prompt for everything
# script.sh a.example.com - prompt for service and action
# script.sh a.example.com smbd - prompt for action
# script.sh a.example.com smbd restart - prompt for nothing

hosts=(a.example.com b.example.com c.example.com)
services=(apache2 mysql smbd)
actions=(stop start restart)

if [[ 3 -eq $# ]]; then
ssh "$1" "sudo service $2 $3"
exit $?
fi

if [[ 2 -eq $# ]]; then
select action in "$actions[@]" "Quit"; do
if [[ "Quit" == "$action" ]]; then
break
fi
ssh "$1" "sudo service $2 $action"
done
exit $?
fi

if [[ 1 -eq $# ]]; then
select svc in "$services[@]" "Quit"; do
select action in "$actions[@]" "Back" "Quit"; do
if [[ "Back" == "$action" ]]; then
break
elif [[ "Quit" == "$action" ]]; then
break 2
fi
ssh "$1" "sudo service $svc $action"
done
done
exit $?
fi

select host in "$hosts[@]" "Quit"; do
select svc in "$services[@]" "Quit"; do
select action in "$actions[@]" "Hosts" "Services" "Quit"; do
if [[ "Services" == "$action" ]]; then
break
elif [[ "Hosts" == "$action" ]]; then
break 2
elif [[ "Quit" == "$action" ]]; then
break 3
fi
ssh "$host" "sudo service $svc $action"
done
done
done





share|improve this answer





























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    This might give you a starting point. Note there is no sanity-checking done here:



    #!/usr/local/bin/bash
    # example invocations:
    # script.sh - prompt for everything
    # script.sh a.example.com - prompt for service and action
    # script.sh a.example.com smbd - prompt for action
    # script.sh a.example.com smbd restart - prompt for nothing

    hosts=(a.example.com b.example.com c.example.com)
    services=(apache2 mysql smbd)
    actions=(stop start restart)

    if [[ 3 -eq $# ]]; then
    ssh "$1" "sudo service $2 $3"
    exit $?
    fi

    if [[ 2 -eq $# ]]; then
    select action in "$actions[@]" "Quit"; do
    if [[ "Quit" == "$action" ]]; then
    break
    fi
    ssh "$1" "sudo service $2 $action"
    done
    exit $?
    fi

    if [[ 1 -eq $# ]]; then
    select svc in "$services[@]" "Quit"; do
    select action in "$actions[@]" "Back" "Quit"; do
    if [[ "Back" == "$action" ]]; then
    break
    elif [[ "Quit" == "$action" ]]; then
    break 2
    fi
    ssh "$1" "sudo service $svc $action"
    done
    done
    exit $?
    fi

    select host in "$hosts[@]" "Quit"; do
    select svc in "$services[@]" "Quit"; do
    select action in "$actions[@]" "Hosts" "Services" "Quit"; do
    if [[ "Services" == "$action" ]]; then
    break
    elif [[ "Hosts" == "$action" ]]; then
    break 2
    elif [[ "Quit" == "$action" ]]; then
    break 3
    fi
    ssh "$host" "sudo service $svc $action"
    done
    done
    done





    share|improve this answer



























      1














      This might give you a starting point. Note there is no sanity-checking done here:



      #!/usr/local/bin/bash
      # example invocations:
      # script.sh - prompt for everything
      # script.sh a.example.com - prompt for service and action
      # script.sh a.example.com smbd - prompt for action
      # script.sh a.example.com smbd restart - prompt for nothing

      hosts=(a.example.com b.example.com c.example.com)
      services=(apache2 mysql smbd)
      actions=(stop start restart)

      if [[ 3 -eq $# ]]; then
      ssh "$1" "sudo service $2 $3"
      exit $?
      fi

      if [[ 2 -eq $# ]]; then
      select action in "$actions[@]" "Quit"; do
      if [[ "Quit" == "$action" ]]; then
      break
      fi
      ssh "$1" "sudo service $2 $action"
      done
      exit $?
      fi

      if [[ 1 -eq $# ]]; then
      select svc in "$services[@]" "Quit"; do
      select action in "$actions[@]" "Back" "Quit"; do
      if [[ "Back" == "$action" ]]; then
      break
      elif [[ "Quit" == "$action" ]]; then
      break 2
      fi
      ssh "$1" "sudo service $svc $action"
      done
      done
      exit $?
      fi

      select host in "$hosts[@]" "Quit"; do
      select svc in "$services[@]" "Quit"; do
      select action in "$actions[@]" "Hosts" "Services" "Quit"; do
      if [[ "Services" == "$action" ]]; then
      break
      elif [[ "Hosts" == "$action" ]]; then
      break 2
      elif [[ "Quit" == "$action" ]]; then
      break 3
      fi
      ssh "$host" "sudo service $svc $action"
      done
      done
      done





      share|improve this answer

























        1












        1








        1







        This might give you a starting point. Note there is no sanity-checking done here:



        #!/usr/local/bin/bash
        # example invocations:
        # script.sh - prompt for everything
        # script.sh a.example.com - prompt for service and action
        # script.sh a.example.com smbd - prompt for action
        # script.sh a.example.com smbd restart - prompt for nothing

        hosts=(a.example.com b.example.com c.example.com)
        services=(apache2 mysql smbd)
        actions=(stop start restart)

        if [[ 3 -eq $# ]]; then
        ssh "$1" "sudo service $2 $3"
        exit $?
        fi

        if [[ 2 -eq $# ]]; then
        select action in "$actions[@]" "Quit"; do
        if [[ "Quit" == "$action" ]]; then
        break
        fi
        ssh "$1" "sudo service $2 $action"
        done
        exit $?
        fi

        if [[ 1 -eq $# ]]; then
        select svc in "$services[@]" "Quit"; do
        select action in "$actions[@]" "Back" "Quit"; do
        if [[ "Back" == "$action" ]]; then
        break
        elif [[ "Quit" == "$action" ]]; then
        break 2
        fi
        ssh "$1" "sudo service $svc $action"
        done
        done
        exit $?
        fi

        select host in "$hosts[@]" "Quit"; do
        select svc in "$services[@]" "Quit"; do
        select action in "$actions[@]" "Hosts" "Services" "Quit"; do
        if [[ "Services" == "$action" ]]; then
        break
        elif [[ "Hosts" == "$action" ]]; then
        break 2
        elif [[ "Quit" == "$action" ]]; then
        break 3
        fi
        ssh "$host" "sudo service $svc $action"
        done
        done
        done





        share|improve this answer













        This might give you a starting point. Note there is no sanity-checking done here:



        #!/usr/local/bin/bash
        # example invocations:
        # script.sh - prompt for everything
        # script.sh a.example.com - prompt for service and action
        # script.sh a.example.com smbd - prompt for action
        # script.sh a.example.com smbd restart - prompt for nothing

        hosts=(a.example.com b.example.com c.example.com)
        services=(apache2 mysql smbd)
        actions=(stop start restart)

        if [[ 3 -eq $# ]]; then
        ssh "$1" "sudo service $2 $3"
        exit $?
        fi

        if [[ 2 -eq $# ]]; then
        select action in "$actions[@]" "Quit"; do
        if [[ "Quit" == "$action" ]]; then
        break
        fi
        ssh "$1" "sudo service $2 $action"
        done
        exit $?
        fi

        if [[ 1 -eq $# ]]; then
        select svc in "$services[@]" "Quit"; do
        select action in "$actions[@]" "Back" "Quit"; do
        if [[ "Back" == "$action" ]]; then
        break
        elif [[ "Quit" == "$action" ]]; then
        break 2
        fi
        ssh "$1" "sudo service $svc $action"
        done
        done
        exit $?
        fi

        select host in "$hosts[@]" "Quit"; do
        select svc in "$services[@]" "Quit"; do
        select action in "$actions[@]" "Hosts" "Services" "Quit"; do
        if [[ "Services" == "$action" ]]; then
        break
        elif [[ "Hosts" == "$action" ]]; then
        break 2
        elif [[ "Quit" == "$action" ]]; then
        break 3
        fi
        ssh "$host" "sudo service $svc $action"
        done
        done
        done






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 9 at 18:32









        DopeGhotiDopeGhoti

        44.4k55684




        44.4k55684












            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Displaying single band from multi-band raster using QGIS

            How many registers does an x86_64 CPU actually have?