LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Bash script require to restart the tomcat on remote server. (https://www.linuxquestions.org/questions/linux-newbie-8/bash-script-require-to-restart-the-tomcat-on-remote-server-4175424702/)

qarar 08-30-2012 01:40 AM

Bash script require to restart the tomcat on remote server.
 
i need a bash scrtip which prompt which server you want to restart the tomcat process suppose i have 3 servers i just run the bash script its prompt three server

1.server1
2.server2
3.server3

if i press 1 its restart the tomcat service on server1.I know that how to ssh the remote server without password.

jschiwal 08-30-2012 01:50 AM

Look at the select statement, followed by a case structure.
Why not simply use which server as an argument to the script (followed by 'case') instead of prompting with a menu? You could even configure bash completion to display the three arguments if you don't remember.

qarar 08-30-2012 01:53 AM

i am using centos 5.5.I dont how to write bash script?

chrism01 08-30-2012 05:00 AM

You need to read these
http://rute.2038bug.com/index.html.gz
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/

wigry 08-30-2012 06:02 AM

I would start by making sure you have a procedure to restart those tomcats. Bash script is just an automation tool but you must be able to restart it manually first. That is yu probably need to SSH into your server and execute shutdown/startup commands.

adinarayanagudla 08-30-2012 06:14 AM

In Ubuntu.
/etc/init.d/apache2 restart
In RedHat
service httpd restart

You can use something like this

#!/bin/bash
ssh $1 /etc/init.d/apache2 restart

qarar 08-30-2012 09:26 AM

this is what i am asking from this forum
 
#!/bin/bash

echo "adserver2 press 2 : "
echo "adserver3 press 3 : "
echo "adserver4 press 4 : "

echo -n "Enter numnber : "
read n

if [ $n -eq 2 ]
then
echo "server 1"
ssh root@10.179.50.46 '/etc/init.d/httpd status && exit'

fi

#else
#if [ $n == 2]
# echo "server 2"
#fi
#
#else

#if [$n == 3]
# echo "server 1"
#fi

chrism01 08-30-2012 07:16 PM

1. Like wigry said, first ensure you've got the right cmd by testing it manually.
You've actually used 'status' when it should be 'start' (or restart).

2. use code tags to post code
https://www.linuxquestions.org/quest...do=bbcode#code

3. I'd recommend using consistent numbering; you're code starts talking about adserver2, then echoes "server 1" ; that's just going to confuse people, inc you ....

4. Read those links in my post #4; they'll show you how to construct a shell script.

naveen.inferno 11-12-2014 07:26 AM

Tomcat not apache server
 
Guys he is asking a different thing He is asking for tomcat and all the answers here are about apache


All times are GMT -5. The time now is 01:38 PM.