Stopping and Starting Multiple services on multiple servers in Linux on same network and doing it by sitting...
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
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.
add a comment |
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
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
add a comment |
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
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
linux shell-script ssh
edited Jan 10 at 19:01
Rui F Ribeiro
39.5k1479133
39.5k1479133
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
add a comment |
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
add a comment |
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
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
answered Jan 9 at 18:32
DopeGhotiDopeGhoti
44.2k55683
44.2k55683
add a comment |
add a comment |
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