LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-30-2012, 01:40 AM   #1
qarar
LQ Newbie
 
Registered: Apr 2011
Posts: 3

Rep: Reputation: 0
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.
 
Old 08-30-2012, 01:50 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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.
 
Old 08-30-2012, 01:53 AM   #3
qarar
LQ Newbie
 
Registered: Apr 2011
Posts: 3

Original Poster
Rep: Reputation: 0
i am using centos 5.5.I dont how to write bash script?
 
Old 08-30-2012, 05:00 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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/
 
Old 08-30-2012, 06:02 AM   #5
wigry
Member
 
Registered: Jul 2004
Distribution: slackware
Posts: 225

Rep: Reputation: 53
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.
 
Old 08-30-2012, 06:14 AM   #6
adinarayanagudla
LQ Newbie
 
Registered: Mar 2011
Location: Bangalore
Distribution: ubuntu
Posts: 4

Rep: Reputation: 0
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
 
Old 08-30-2012, 09:26 AM   #7
qarar
LQ Newbie
 
Registered: Apr 2011
Posts: 3

Original Poster
Rep: Reputation: 0
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
 
Old 08-30-2012, 07:16 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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.
 
Old 11-12-2014, 07:26 AM   #9
naveen.inferno
LQ Newbie
 
Registered: Oct 2013
Posts: 1

Rep: Reputation: Disabled
Tomcat not apache server

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


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] script to restart Tomcat . . . dgg Programming 6 12-19-2011 03:40 PM
Require a script to connect to a remote system from windows xp. vankayalarohit Linux - Newbie 1 09-08-2011 05:18 AM
Bash script to read .txt files on a remote Windows 2003 R2 server via FTP laurens Linux - Newbie 25 05-15-2009 06:01 AM
Script to restart application services on remote systems vinayhr Programming 3 09-04-2006 12:37 AM
Remote Restart Tomcat PerfectReign Linux - Security 2 05-16-2005 11:33 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration