LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-12-2018, 03:44 PM   #1
rcroyal88
LQ Newbie
 
Registered: Jun 2018
Posts: 11

Rep: Reputation: Disabled
Check server status along with process id and specific text in log untill 5 minutes


Hi ,

I want to check the server status up and running .
1. Check based upon process id.
2. While checking status Grep specific text in log files untill 5 minutes ,else exit.

3. After start chek if starts or ot

4. After stop check if stops or not

*******I am working below script***************************

Code:
case "$1"in

start )

    cd /home/opt/jpo/org
      ./uikli.sh

     ;;

 Status)

if [ -n "$pid"] ;  then 

# Here i want to check aso from log.txt for text  "pogo Go" this takes 5 minutes to come in log.txt. If this condition is tur then only server is started.

echo "Server is running"

elif [ -z "$pid" ] ; the 

echo " Server is  stopped "

   ;;

STOP )

  cd /home/opt/jpo/org
      ./uikli.sh stop
   
       while [ `ps -o pid= -p $pid| wc -l` -ne 0 ] ; do
       sleep 1
       done

    echo " done"
    
   ;;

*)


echo"Usage $0 {start|stop|status}

exit 1

;;

esac

Last edited by rcroyal88; 10-13-2018 at 03:09 AM.
 
Old 10-12-2018, 03:48 PM   #2
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,735

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
Does that script work? If not, what happens?

(Please use [code] tags when posting code)
 
Old 10-12-2018, 03:54 PM   #3
rcroyal88
LQ Newbie
 
Registered: Jun 2018
Posts: 11

Original Poster
Rep: Reputation: Disabled
Yes script works fine, here in status I want to check specific text in log file untill 5 minutes and if it can find then its runnng else stopped.


Status)

if [ -n "$pid"] ; then

echo "Server is running"
 
Old 10-12-2018, 04:39 PM   #4
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,735

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
What text and in which log file?
At that point, you know the process is running.
If you want to stop it after 5 seconds, will sleep do?
Code:
man sleep
 
Old 10-12-2018, 07:48 PM   #5
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206
Please place your code snippets inside [CODE]...[/CODE] tags for better readability. You may type those yourself or click the "#" button in the edit controls.

It is unclear what you mean by this...

Quote:
Originally Posted by rcroyal88 View Post
...I want to check specific text in log file untill 5 minutes and if it can find then its runnng else stopped.
Do you mean you want to look for existence of a specific line in some log file within the previous 5 minutes?

Please be more complete in your question, including which log and an actual example of the line you want to look for.

Please review the Site FAQ for guidance in posting your questions and general forum usage. Especially, read the link in that page, How To Ask Questions The Smart Way. The more effort you put into understanding your problem and framing your questions, the better others can help!
 
Old 10-13-2018, 03:09 AM   #6
rcroyal88
LQ Newbie
 
Registered: Jun 2018
Posts: 11

Original Poster
Rep: Reputation: Disabled
Edited code with readable format now .
 
Old 10-15-2018, 01:03 PM   #7
rcroyal88
LQ Newbie
 
Registered: Jun 2018
Posts: 11

Original Poster
Rep: Reputation: Disabled
# Here i want to check aso from log.txt for text "pogo Go" this takes 5 minutes to come in log.txt. If this condition is tur then only server is started.
 
Old 10-15-2018, 04:39 PM   #8
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,269
Blog Entries: 24

Rep: Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206Reputation: 4206
Quote:
Originally Posted by astrogeek View Post
Please be more complete in your question, including which log and an actual example of the line you want to look for.
You have told us nothing at all about how the lines in the file are, or are not timestamped, so it is impossible for anyone to even guess how to test for the 5 minute window.

Again, please review the Site FAQ for guidance in posting your questions and general forum usage. Especially, read the link in that page, How To Ask Questions The Smart Way. The more effort you put into understanding your problem and framing your questions, the better others can help!
 
Old 10-16-2018, 09:57 AM   #9
rcroyal88
LQ Newbie
 
Registered: Jun 2018
Posts: 11

Original Poster
Rep: Reputation: Disabled
Log file looks like this as below
I want my script to check for 5 minutes and search this string "POGO ready" . If it can find this string for 5 minutses else exit

Code:
2018-10-04T12:09:31 [main]info initiating
2018-10-04T12:10:31 [main]info initiating2
2018-10-04T12:11:31 [main]info initiating3
2018-10-04T12:13:31 [main]info initiating4
2018-10-04T13:09:31 [main]info initiating5
2018-10-04T13:09:31 [main]info initiating6
2018-10-04T14:09:31 [main]info initiating7
2018-10-04T14:09:31 [main]info initiating8
2018-10-04T14:09:31 [main]info  Connected sql
2018-10-04T15:09:31 [main]POGO ready
 
  


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
Logic to count per minutes hits on web-server log. pix9 Programming 12 03-23-2016 07:38 AM
How can I check the server status? baesan Linux - Server 2 11-30-2014 07:49 PM
How to check RAID 1 status on IBM HS 21 Blade Server jv83 Linux - Hardware 1 04-28-2014 03:16 AM
How to restart & check status of ssh server bostonantifan Ubuntu 3 10-30-2007 11:06 AM
Need program/script to check server status thetawaverider Linux - Software 1 02-27-2007 12:58 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:21 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