LinuxQuestions.org
Visit the LQ Articles and Editorials section
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 04-28-2013, 03:41 AM   #1
figure20012
Member
 
Registered: Apr 2012
Posts: 75

Rep: Reputation: Disabled
automating server startup tomcat in bash


while ["true" ]; do tail -n 3 catalina.out; sleep 1 ; if [ `tail -n 3 catalina.out | sed -n '/startup/p'` ] then break; echo "tomcat server started";fi clear; done

Can some please suggest why the bash command is not working please?
 
Old 04-28-2013, 05:04 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,492
Blog Entries: 54

Rep: Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910
By the looks of it: missing space, missing semicolon, relative file path, unknown log file contents.
Run your script as
Code:
/bin/bash -xv /path/to/script 2>&1 | tee /tmp/script.txt
That should give you debug output in "/path/to/script" to figure things out.
If unsure attach it and add a description of where you think it fails.
 
Old 04-28-2013, 05:10 AM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Rep: Reputation: 285Reputation: 285Reputation: 285
Just try this, and let's know the error, if any:
Code:
while true; do tail -n 3 catalina.out; sleep 1; if [ `tail -n 3 catalina.out | sed -n '/startup/p'` ]; then; break; echo "tomcat server started"; fi; clear; done
Or create a script and invoke it:
Code:
#!/bin/bash
while true
do
tail -n 3 catalina.out
sleep 1
   if [ `tail -n 3 catalina.out | sed -n '/startup/p'` ]; then
   break
   echo "tomcat server started"
   fi
clear
done

Last edited by shivaa; 04-28-2013 at 05:13 AM.
 
Old 04-28-2013, 05:51 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,492
Blog Entries: 54

Rep: Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910
Shame, really. Doesn't teach him anything...
 
Old 04-28-2013, 07:47 AM   #5
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Rep: Reputation: 285Reputation: 285Reputation: 285
Quote:
Originally Posted by unSpawn View Post
Shame, really. Doesn't teach him anything...
In what sense you're saying this... Did we miss anything?
 
Old 04-28-2013, 08:32 AM   #6
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,301

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
I think UnSpawn meant that by telling the OP to use '-xv' switches, he would be likely to be able to figure it out for himself, as well as learning how to debug bash.
 
3 members found this post helpful.
Old 04-28-2013, 10:49 AM   #7
figure20012
Member
 
Registered: Apr 2012
Posts: 75

Original Poster
Rep: Reputation: Disabled
Thanks for helping me.

#!/bin/bash
while [ true ]
do
res=`tail -n 1 catalina.out`
if [ `echo $res | grep start ` ];then
break
echo "tomcat server startup"
fi
sleep 2
clear
done

I am having error when server startup appears at the end of catalina.out.If i put only startup the loop breaks.

I am getting the following error
script.sh: line 6: [: server: unary operator expected
 
Old 04-28-2013, 11:00 AM   #8
figure20012
Member
 
Registered: Apr 2012
Posts: 75

Original Poster
Rep: Reputation: Disabled
it works now
the problem was with the if condition

if [ "`echo $res | grep start`" ]

thank you all
 
Old 04-28-2013, 11:54 AM   #9
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,797
Blog Entries: 4

Rep: Reputation: 285Reputation: 285Reputation: 285
Good. In case if it has solved, you can mark the thread as solved (option is available under Thread Tools on top menu).

Here is a guide which will be helpful for you: http://tldp.org/LDP/abs/abs-guide.pdf
 
Old 04-28-2013, 03:04 PM   #10
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,492
Blog Entries: 54

Rep: Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910Reputation: 2910
Quote:
Originally Posted by chrism01 View Post
I think UnSpawn meant that by telling the OP to use '-xv' switches, he would be likely to be able to figure it out for himself, as well as learning how to debug bash.
Indeed, because being able to debug them should be a basic skill anyone who handles scripts should have.


People ignoring debug mode (or not pointing them to it) leads to the OP posting stuff like this:
Quote:
Originally Posted by figure20012 View Post
Code:
script.sh: line 6: [: server: unary operator expected
as debug mode would actually show how BASH parses things (efficiency thing).


Quote:
Originally Posted by shivaa View Post
Good. In case if it has solved
Not so fast.

You're an admin so you should understand the implications of greedy matches:
Code:
if [ "`echo $res | grep start`" ]
and while the 'sleep' slows searching down "start" still matches any of:
Code:
^.*org\.apache\.catalina\.startup.*$
(which can be quite a lot) and the only full message the OP should be looking for is:
Code:
^INFO:.Server.startup.in.*ms$

This means the script could look like this (no grep reqqed):
Code:
#!/bin/bash
while [ true ]; do sleep 2s
 OUTPUT=$(tail -n 1 catalina.out); REGEX="INFO: Server startup in"
 [[ $RES =~ $REGEX ]] && { echo "Tomcat started."; break; }
done
exit 0

Some BASH scripting guides:
http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
http://www.tldp.org/LDP/Bash-Beginne...tml/index.html
http://www.gnu.org/software/bash/man...ode/index.html
http://www.grymoire.com/Unix/Sh.html
http://www.tldp.org/LDP/abs/html/
http://mywiki.wooledge.org/BashFAQ
http://mywiki.wooledge.org/BashPitfalls
 
1 members found this post helpful.
  


Reply

Tags
bash, tomcat


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Bash script require to restart the tomcat on remote server. qarar Linux - Newbie 7 08-30-2012 07:16 PM
how to start mysql server & apache server at startup and then tomcat at last at boot sanjay87 Linux - Server 5 06-16-2012 08:19 AM
Errors on tomcat Server startup and shutdown log tanveer Linux - Server 3 07-16-2008 01:07 AM
Automating clamav startup kaplan71 Suse/Novell 1 07-28-2006 12:16 AM
TOMCAT init script not working on startup -- tomcat 4.x / Mandrake Linux 8.0 jmartinph Mandriva 0 03-08-2004 01:31 AM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration