Find the answer to your Linux question:
Results 1 to 6 of 6
Hey Gang- I'm wanting to write a script to run some commands and I wanted to do a for while loop that checks the current time to make sure it ...
  1. #1
    Just Joined!
    Join Date
    Jun 2008
    Posts
    5

    Execute commands in bash/ksh between two times

    Hey Gang-

    I'm wanting to write a script to run some commands and I wanted to do a for while loop that checks the current time to make sure it falls between two static times.... lets say between 10:00 and 14:00.

    Is there an easy way to do this? Or maybe it should be done outside the script?

    Thanks!

  2. #2
    Just Joined! geniuz's Avatar
    Join Date
    Mar 2008
    Location
    Netherlands, Europe
    Posts
    71
    If I get you correctly you want a script to run at a certain time ?

    If so, you must use a crontab:
    simply do crontab -e in your terminal
    and add a line like this:
    * * * * * /path/to/your/script

    where the * respectively represent the: minute (0-59), hour(0-23), day of month(1-31), month(1-12), day of week(0-6) (where 0=sunday)

  3. #3
    Just Joined!
    Join Date
    Jun 2008
    Posts
    5
    Well, yes and no. I want it to start at a specific time, but I also want to make sure it stops at a specific time. I want to make sure this script isn't running when the server is busy with other processes.

    I just want to declare my start and stop times up front, but I'm not sure how to phrase the if then statement to check to see if the current time is between those two.


  4. #4
    Just Joined!
    Join Date
    Jun 2008
    Posts
    5
    Any help would be greatly appreciated. Thanks!!

  5. #5
    Just Joined! geniuz's Avatar
    Join Date
    Mar 2008
    Location
    Netherlands, Europe
    Posts
    71
    You got just add two crontabs, one with the command to start your desired process at a given time and one with a command to kill your process at a given time.

  6. #6
    Linux Engineer Freston's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    1,047
    Quote Originally Posted by idiotboy
    I want to make sure this script isn't running when the server is busy with other processes.
    Just tell your script to be nice

    Code:
    man nice
    Can't tell an OS by it's GUI

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...