Page 5 of 5 FirstFirst ... 345
Results 41 to 48 of 48

Thread: Cron With if Condition possible?

  1. #41
    Join Date
    Aug 2013
    Beans
    23

    Re: Cron With if Condition possible?

    BINGO! It's working perfectly and I can't thank you enough.

    At first nothing, it wasn't working with;
    Code:
    44 17 * * * sudo /home/dave/hibernate.sh > /dev/pts/0
    I then just tryed:
    Code:
    sudo bash /home/dave/hibernate.sh
    An like before it worked in bash but not crontab.

    So what the heck I changed:
    Code:
    44 17 * * * sudo /home/dave/hibernate.sh > /dev/pts/0
    to
    Code:
    44 17 * * * sudo bash /home/dave/hibernate.sh
    BAM! works like a charm. Below is the info you requested.


    Code:
    $ ls -al ~ | grep hibernate
    -rwx------   1 root root     528 Sep  5 17:21 hibernate_cron.tab
    -rw-rw-r--   1 dave dave       0 Sep  4 18:03 hibernate_cron.tab~
    -rwxrwxr-x   1 dave dave     929 Sep  2 07:07 hibernateonnetwork.py~
    -rw-rw-r--   1 dave dave       0 Aug 31 17:04 hibernate.py~
    -rwxrwxr-x   1 dave dave     963 Aug 31 17:52 hibernateserver.py~
    -rwx------   1 root root    1803 Sep  5 18:20 hibernate.sh
    -rwxrwxr-x   1 dave dave    1259 Sep  3 21:30 hibernate.sh~
    -rwxrwxr-x   1 dave dave     929 Sep  2 07:06 hibernatetest.py~

  2. #42
    Join Date
    Oct 2010
    Location
    Above ground...(for now)
    Beans
    761

    Re: Cron With if Condition possible?

    Good job, Dave...nice debug there. My guess it that I didn't need to use bash in the crontab because of what's in my root PATH environment variable. No biggy though. Glad you got it working.
    The output I asked for looks good as well.

    I should tell you that if you ever call a script from root's crontab in the future, you should make root the owner of it AND change its permission level to 700. Otherwise, you could be leaving you computer at risk of being completely "owned" by a malicious hacker. Part of the reason for this is that root can run sudo without providing a password, which is why we had to call the script from root's crontab.

    I am in the process of writing up some notes for you on "tuning" the network activity parameters in the script. They aren't ready yet.

    Oh, did you see any output coming to your terminal window when the cronjob ran?
    Last edited by Crusty Old Fart; September 6th, 2013 at 05:59 AM.
    Suffering from severe chronic female supervision deficiency syndrome resulting in
    an increasing intolerance of adolescent scatological effluence and PMS induced nefarious diatribe.
    How to: Mark your thread as: [SOLVED]

  3. #43
    Join Date
    Aug 2013
    Beans
    23

    Re: Cron With if Condition possible?

    Again I can't thank you enough. I really appreciate you taking the time, not only to put together the script but taking the time to teach and explain how and why it works.

    When the crontab runs I didn't see any output however, when I ran the script in the terminal got:
    Code:
    Accumulated Inbound Tcp Segments = 5                 
    
    Hibernating...
    This may take several seconds
    and your screen may blink before shutting down.
    Please wait...
    
    
    Shutting down...
    This may take several more seconds.
    Please wait...

  4. #44
    Join Date
    Oct 2010
    Location
    Above ground...(for now)
    Beans
    761

    Re: Cron With if Condition possible?

    Yeah...I just noticed that before your post came in. The reason is that you removed the code I had written to redirect the output from cron to your terminal, which is what the blue code in the box below does. I did this to make tuning the network parameters easier. You might want to fix this line in root's crontab, as well as in the hibernate_cron.tab file:
    Code:
    44 17 * * * sudo bash /home/dave/hibernate.sh > /dev/pts/0
    This sends the output to the terminal window running from file: /dev/pts/0

    The following command will cause a terminal window to tell you what file its running from:
    Code:
    tty
    If it tells you something that isn't: /dev/pts/0 , you can close all your terminal windows, and open another one up. The new window should be running from file /dev/pts/0 then. And cron will send its output to it.

    You're quite the little hacker, Buddy
    Last edited by Crusty Old Fart; September 6th, 2013 at 07:03 AM.
    Suffering from severe chronic female supervision deficiency syndrome resulting in
    an increasing intolerance of adolescent scatological effluence and PMS induced nefarious diatribe.
    How to: Mark your thread as: [SOLVED]

  5. #45
    Join Date
    Oct 2010
    Location
    Above ground...(for now)
    Beans
    761

    Re: Cron With if Condition possible?

    Quote Originally Posted by mutiny2 View Post
    Again I can't thank you enough. I really appreciate you taking the time, not only to put together the script but taking the time to teach and explain how and why it works.
    ...
    Wow, Dave. What a nice thing to write. Thank you very much. It feels good to be appreciated. I really appreciate you expressing your appreciation.

    I should apologize for my ineptitude and any confusion I may have caused you, or anyone else reading this thread, once we got into working on cron. It has been years since I've been immersed so deeply into the intricacies of that area of Unix. Unfortunately, I fell flat on my face with it. In order to prevent leading anyone astray who may read this thread later, I've gone back and edited my postings to point out where I was wrong and was under the impression that certain things were true, when in fact, they were not. Very sorry about all that.
    Last edited by Crusty Old Fart; September 6th, 2013 at 04:23 AM. Reason: Added apology.
    Suffering from severe chronic female supervision deficiency syndrome resulting in
    an increasing intolerance of adolescent scatological effluence and PMS induced nefarious diatribe.
    How to: Mark your thread as: [SOLVED]

  6. #46
    Join Date
    Oct 2010
    Location
    Above ground...(for now)
    Beans
    761

    A few notes on tuning the script

    The script detects incoming Tcp segments whether they are coming from a machine on your home network (LAN) or the Internet (WAN) or both.

    In order to have the number of incoming Tcp segments detected drop to zero, there must not be any incoming data from the LAN or the WAN. Even if you aren't intentionally streaming anything in from the Internet, you may still receive incoming Tcp segments if: your email client is running and is automatically checking for new mail periodically and/or your browser is open to a web page that has been coded to automatically update periodically -- several news related websites do this.

    Since the script won't hibernate until the number of incoming Tcp segments drops below the minimum setting of the parameter: Tcpmin, WAN traffic may prevent hibernation if you set Tcpmin too low and/or allow too many Tcp segments to accumulate by setting the parameter: Tcptime too high.

    Conversely, if Tcpmin is set too high and/or Tcptime is set too low, the script could force premature hibernation.

    The frequency at which the script checks the Tcp traffic is controlled by specifying the interval of time to elapse between checks. This is done by changing the value assigned to the parameter: Checktime.

    Tuning these parameters is done by editing hibernate.sh and changing their values. The block of code where these parameters are set is now more conspicuously marked with a banner heading in the file as follows:
    Code:
    # +-------------------------------------------------------------------+
    # | Parameter settings may be changed in the following block of code. |
    # +-------------------------------------------------------------------+
    
    # Set the interval (in minutes) between retries to count the number of accumulated inbound Tcp segments.
      Checktime='15m'
    
    # Set the time duration (in seconds, the default) to accumulate inbound Tcp segments.
      Tcptime=5
    
    # Set the minimum number of accumulated inbound Tcp segments required to prevent hibernation.
      Tcpmin=1000
    Below this block of code is another banner that warns against editing the code below it. This code is somewhat cryptic and can be easily broken by someone unfamiliar with some of the more advanced techniques in bash, like using extended globbing to enhance the string trimming capabilities of parameter expansion. The warning, unapologetically, looks like this:
    Code:
    # +------------------------------------------------------------------------------+
    # | Do not edit any of the code below unless you know EXACTLY what you're doing. |
    # +------------------------------------------------------------------------------+
    I think that about wraps it up for me, Dave.
    It's been a pleasure working with you on this little project.
    I've really enjoyed it.

    I'll stay subscribed to this thread for another week or so, and will be happy to answer any further questions you may have.

    In the meantime, I'll leave you with my buddy, Darthroy.
    May the force be with you.

    Crusty
    Code:
                             _---_
                            /_/|\_\
                           (/-O^O-\)
                    __    /_\\/*\//_\    __
             ------vVVv----- o###o -----vVVv------
                              """
    
                       Darthroy was here.
    Last edited by Crusty Old Fart; September 6th, 2013 at 07:04 AM.
    Suffering from severe chronic female supervision deficiency syndrome resulting in
    an increasing intolerance of adolescent scatological effluence and PMS induced nefarious diatribe.
    How to: Mark your thread as: [SOLVED]

  7. #47
    Join Date
    Aug 2013
    Beans
    2

    Re: Cron With if Condition possible?

    i think this is what im looking for, but.... ....is it possible to add a ping query? so that my server dont shutdown if a computer in my network is "online"?

  8. #48
    Join Date
    Sep 2011
    Beans
    Hidden!

    Re: Cron With if Condition possible?

    X

Page 5 of 5 FirstFirst ... 345

Tags for this Thread

Bookmarks

Posting Permissions

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