LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Check server status along with process id and specific text in log untill 5 minutes (https://www.linuxquestions.org/questions/programming-9/check-server-status-along-with-process-id-and-specific-text-in-log-untill-5-minutes-4175640256/)

rcroyal88 10-12-2018 03:44 PM

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


scasey 10-12-2018 03:48 PM

Does that script work? If not, what happens?

(Please use [code] tags when posting code)

rcroyal88 10-12-2018 03:54 PM

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"

scasey 10-12-2018 04:39 PM

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

astrogeek 10-12-2018 07:48 PM

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 (Post 5914133)
...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!

rcroyal88 10-13-2018 03:09 AM

Edited code with readable format now .

rcroyal88 10-15-2018 01:03 PM

# 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.

astrogeek 10-15-2018 04:39 PM

Quote:

Originally Posted by astrogeek (Post 5914179)
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!

rcroyal88 10-16-2018 09:57 AM

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



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