LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 03-08-2017, 12:33 AM   #1
hack3rcon
Senior Member
 
Registered: Jan 2015
Posts: 1,432

Rep: Reputation: 11
Post Shutdown command with specific Date and Time


Hello.
How can I shutdown my system via "shutdown" command in specific Date and Time? I know that with "shutdown -h " I can specific a hours but how about Date?
For example, I want to shutdown my system at 23:00 tomorrow.


Thank you.
 
Old 03-08-2017, 12:39 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 7.7 (?), Centos 8.1
Posts: 18,235

Rep: Reputation: 2709Reputation: 2709Reputation: 2709Reputation: 2709Reputation: 2709Reputation: 2709Reputation: 2709Reputation: 2709Reputation: 2709Reputation: 2709Reputation: 2709
Try the 'at' cmd; its good for one shot deals. For regular ones, cron is popular.
 
1 members found this post helpful.
Old 03-08-2017, 04:11 AM   #3
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 1,984

Rep: Reputation: 386Reputation: 386Reputation: 386Reputation: 386
edit /etc/crontab

59 23 * * * root shutdown -h now

Shutdown the machine everyday at 11:59PM

--------------

shutdown -h +30 "Server is going to shutdown 30 minutes from now, save your work or delete all your files."

Last edited by JJJCR; 03-08-2017 at 04:13 AM. Reason: edit
 
Old 03-08-2017, 06:59 AM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 24,364

Rep: Reputation: 5456Reputation: 5456Reputation: 5456Reputation: 5456Reputation: 5456Reputation: 5456Reputation: 5456Reputation: 5456Reputation: 5456Reputation: 5456Reputation: 5456
In addition for the date you can specify the day of the week i.e thu (4) or day of the month i.e 9. Tomorrow being Thursday and the ninth day of the March.

It is also possible to use the date command for a specific date.
 
Old 03-09-2017, 02:09 AM   #5
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6051Reputation: 6051Reputation: 6051Reputation: 6051Reputation: 6051Reputation: 6051Reputation: 6051Reputation: 6051Reputation: 6051Reputation: 6051Reputation: 6051
from "man shutdown":
Code:
 shutdown may be used to halt, power-off or reboot the machine.

       The first argument may be a time string (which is usually "now").
 
Old 03-09-2017, 04:35 AM   #6
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924Reputation: 2924
Quote:
Originally Posted by ondoho View Post
from "man shutdown":
Code:
 shutdown may be used to halt, power-off or reboot the machine.

       The first argument may be a time string (which is usually "now").
Yes, but it goes on to say:

Code:
The time string may either be in the format "hh:mm" for hour/minutes
       specifying the time to execute the shutdown at, specified in 24h clock
       format. Alternatively it may be in the syntax "+m" referring to the
       specified number of minutes m from now.  "now" is an alias for "+0",
       i.e. for triggering an immediate shutdown. If no time argument is
       specified, "+1" is implied.
The OP wants to shutdown with a specific date and time (and I'm sure doesn't want to have to calculate how many minutes ahead that particular date/time is).
 
Old 03-09-2017, 09:22 AM   #7
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 4,716

Rep: Reputation: 2191Reputation: 2191Reputation: 2191Reputation: 2191Reputation: 2191Reputation: 2191Reputation: 2191Reputation: 2191Reputation: 2191Reputation: 2191Reputation: 2191
Quote:
Originally Posted by hydrurga View Post
(and I'm sure doesn't want to have to calculate how many minutes ahead that particular date/time is).
Yes, that would be so hard to put in a script:
Code:
#!/bin/bash
Flags=
while [[ "$1" =~ ^- ]]; do
    Flags="$Flags $1"
    shift
done
When=$(date -d "$1" +%s) || exit
shift
shutdown $Flags +$(((When - $(date +%s))/60)) $*
Then you can run
Code:
myshutdown -P "11:30PM next Tuesday" OMG it\'s almost Wednesday

Last edited by rknichols; 03-09-2017 at 09:25 AM.
 
1 members found this post helpful.
Old 03-11-2017, 09:28 AM   #8
hack3rcon
Senior Member
 
Registered: Jan 2015
Posts: 1,432

Original Poster
Rep: Reputation: 11
Quote:
Originally Posted by chrism01 View Post
Try the 'at' cmd; its good for one shot deals. For regular ones, cron is popular.
Can you show me an example of "at" ?
 
Old 03-11-2017, 01:27 PM   #9
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6051Reputation: 6051Reputation: 6051Reputation: 6051Reputation: 6051Reputation: 6051Reputation: 6051Reputation: 6051Reputation: 6051Reputation: 6051Reputation: 6051
Quote:
Originally Posted by hack3rcon View Post
Can you show me an example of "at" ?
https://duckduckgo.com/?q=linux+example+of+at
 
1 members found this post helpful.
Old 03-11-2017, 01:44 PM   #10
wpeckham
Senior Member
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 4,917

Rep: Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400
Quote:
Originally Posted by chrism01 View Post
Try the 'at' cmd; its good for one shot deals. For regular ones, cron is popular.
I never set up cron to reboot or shutdown a machine, but I do use 'at' for this purpose often.
Example:
Code:
echo "shutdown -r now" | at 23:59
Check the man page and online examples linked in other postings here for ways to express exact dates and times for the 'at' command. This is a very useful technique.
 
Old 03-14-2017, 08:15 AM   #11
hack3rcon
Senior Member
 
Registered: Jan 2015
Posts: 1,432

Original Poster
Rep: Reputation: 11
Quote:
Originally Posted by wpeckham View Post
I never set up cron to reboot or shutdown a machine, but I do use 'at' for this purpose often.
Example:
Code:
echo "shutdown -r now" | at 23:59
Check the man page and online examples linked in other postings here for ways to express exact dates and times for the 'at' command. This is a very useful technique.
Why not use "shutdown -h 23:59" ?
 
Old 03-14-2017, 12:29 PM   #12
wpeckham
Senior Member
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 4,917

Rep: Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400Reputation: 2400
Quote:
Originally Posted by hack3rcon View Post
Why not use "shutdown -h 23:59" ?
A couple of reasons:
1. I can control at both remotely and on the terminal easier, in the case I change my mind.
2. This works the same on all of my machines, while some of them have 'shutdown' commands that specify parameters differently.

I am used to running a mixed bag of RHEL, CentOS, Debian, SUSE, Ubuntu Server, AIX, HP-UX, Tru64Unix, and a couple less usual. (No more SCO, thank goodness!) The versions are all over the place, and some of them implement 'shutdown' as an executable, others as scripts. I had created a local manual of the "things that work everywhere except Windows" at my last workplace: this was one item in that document.

There is not likely to be any good reason for avoiding the form above as long as you are running any currently supported Linux version with near standard GNU utilities. I would just check your local man pages first, to be sure your environment is one where that does what you want. I HATE dragging a newbie into version limbo or giving advice that fails them. I figure they (mostly) deserve better from me. And that is all there is about that.

Meanwhile, back at the forums ...
 
  


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
mv files with specific date/time and count sunny singhal Linux - Newbie 1 01-16-2016 09:09 AM
IsThere a fridge, that we can program at specific date/time to unfreeze specific food frenchn00b General 3 07-21-2009 11:26 PM
How to create an executable script that starts execution at a specific date and time? jtag Linux - General 3 08-12-2008 08:36 PM
Command line: How do I backup files modified after a specific date only rm_-rf_windows Linux - General 2 06-28-2007 08:34 PM
Automate Shutdown At Specific Time RemusX2 Linux - General 5 06-27-2006 09:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:34 AM.

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