LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 09-20-2017, 10:02 PM   #1
bmxakias
Member
 
Registered: Jan 2016
Posts: 45

Rep: Reputation: Disabled
Question How to get Nginx restart timestamp and upon this run a command or not?


Hello

I am looking for a way for my bash script file.sh to do a check if Nginx was restarted X seconds or minutes ago to run a command or not:

something like:

Code:
if check if nginx restart was restart 30 minutes ago and if yes do nothing or if no run this command
then
   do nothing
else 
   run this command
fi
Any help please?

Thank you

Last edited by bmxakias; 09-21-2017 at 02:03 PM.
 
Old 09-20-2017, 10:27 PM   #2
bmxakias
Member
 
Registered: Jan 2016
Posts: 45

Original Poster
Rep: Reputation: Disabled
Ok i found a way to check when it was restarted using the pid file like:

Code:
ls -l /usr/local/nginx/logs/nginx.pid

the output is:

Code:
-rw-r--r-- 1 root root 6 Sep 21 06:21 /usr/local/nginx/logs/nginx.pid
so now i want to compare that time with current server time and if it is lower than X minutes do nothing or if it is higher than X minutes run a command.

Last edited by bmxakias; 09-20-2017 at 10:29 PM.
 
Old 09-22-2017, 11:17 AM   #3
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 705

Rep: Reputation: 425Reputation: 425Reputation: 425Reputation: 425Reputation: 425
Hi.

This SO discussion may be helpful: how to compare file timestamps in bash
 
2 members found this post helpful.
Old 09-22-2017, 11:56 AM   #4
bmxakias
Member
 
Registered: Jan 2016
Posts: 45

Original Poster
Rep: Reputation: Disabled
Thank you
 
  


Reply


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
Centos 6.6 /etc/init.d/rc.local doesn't run the command after restart ASTRAPI Linux - Newbie 10 01-27-2015 10:01 AM
[SOLVED] timestamp of command history doesn't show time command was executed? UprLftCstr Linux - Newbie 3 04-17-2014 12:31 PM
[SOLVED] Restart FreeRadius from PHP Script (Run command as another user) buee Linux - Software 0 06-01-2012 11:39 AM
In FC6 network interface doesn't come up if 'service network restart' command is run rajat Linux - Networking 2 05-02-2007 11:53 PM
shell timestamp command lowspeed Linux - General 2 02-17-2005 04:19 PM

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

All times are GMT -5. The time now is 07:38 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration