Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 09-20-2017, 10:02 PM   #1
Registered: Jan 2016
Posts: 116

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


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

something like:

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

Thank you

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

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

ls -l /usr/local/nginx/logs/

the output is:

-rw-r--r-- 1 root root 6 Sep 21 06:21 /usr/local/nginx/logs/
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
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 709

Rep: Reputation: 427Reputation: 427Reputation: 427Reputation: 427Reputation: 427

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
Registered: Jan 2016
Posts: 116

Original Poster
Rep: Reputation: Disabled
Thank you


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 > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:39 PM.

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