• Status: Solved
  • Priority: High
  • Security: Public
  • Views: 92
  • Last Modified:

Sleep command wait till tomorrow

sleep command wait till tomorrow 7:00 am .

Below command not work for me

    endTime=$(date -d "Tomorrow 07:00AM" +%s)
    sleep $endTime

Open in new window


i know can add second for sleep command but how can i tell to sleep wait till Tomorrow 7:00 Am ?
0
Mehran Goudarzi
Asked:
Mehran Goudarzi
6 Solutions
 
Nitin SontakkeDeveloperCommented:
I have virtually no knowledge on the topics of the thread, but never seen anyone asking process to sleep for that long.

Which is the operating system? Why not resort to Scheduled Task / Cron job, or similar.
0
 
Mehran GoudarziAuthor Commented:
    startTime=$(date +%s)
    endTime=$(date -d "tomorrow 07:30:00" +%s) 
    timeToWait=$(($endTime- $startTime))
    sleep $timeToWait

Open in new window


This helped me Thanks .
0
 
Julian HansenCommented:
I would argue the correct way of doing this is with a CRON job.

There are many reasons why you should not rely on a sleep function to do this.

CRON jobs are precisely for this scenario - set them up to run when they need to and have your script do what needs to be done as quickly as possible.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
nociSoftware EngineerCommented:
If the process gets killed, (f.e. system reboot) then the sleep terminates and never will wake up.
cron or at  (atd task) will take care of that...
1
 
gr8gonzoConsultantCommented:
I concur with the other comments that you should not be letting a process sleep for this long. You are just begging for more problems later on. A scheduler like cron should be used here.
1
 
Bernard S.CTOCommented:
THe fact that the asker solution "did work" is fine. However, as spotted by other experts this is not the right way to do it.

As spotted by @noci the (only single) correct way to do this is with an atd/at job
Cron is better suited for repetitive job, which is not the case here
0
 
gr8gonzoConsultantCommented:
While it might not be the right way to do it, I wouldn't suggest objecting to the closure. If an OP wants to do something against the recommendations of several experts, then that might be the only way for him/her to learn (or there's a slight chance that the OP knows and has not shared contextual information that invalidates the expert recommendations). I'd recommend letting the question close if that's what the OP decides to do.
2
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now