10

So I have a collection of scripts which are used to control my reciever and tv power during certain events like boot, screensaver, and remote control. One of these is executed during login but the thing is maybe I don't want it to run the script when the machine is scheduled to power up. I have the logic to ignore events if blanked = 0 during execution of startup apps, hence it wont send ir during boot or shutdown. How can I accomplish this through the use of cron? I choose cron because those events happen before startup applications. Cron is awesome but as far as I understand I can only run at boot or on a schedule not both. I need to script the time variable but I'm not sure how.

syson.sh (called during login as a startup app and screen state change)

#!/bin/sh
cd /home/gilson585/
blanked=`cat blanked`
if [ $blanked -eq 0 ] ; then
    blanked=1;echo $blanked > blanked
else
    irsend SEND_ONCE VR4085DF KEY_POWER;irsend SEND_ONCE Kenwood_RC-R0813 power;blanked=0;echo $blanked > blanked
    sleep 1
    irsend SEND_ONCE Kenwood_RC-R0813 cd/dvd
fi

sysoff.sh (called during shutdown as part of lirc init.d script and screen state change)

#!/bin/sh
cd /home/gilson585/
blanked=`cat blanked`
if [ $blanked -eq 0 ] ; then
    irsend SEND_ONCE Kenwood_RC-R0813 power;irsend SEND_ONCE VR4085DF KEY_POWER;blanked=1;echo $blanked > blanked
fi

xscreensaver.sh (screensaver watchdog, called during login)

#!/bin/bash
cd /home/gilson585/
xscreensaver-command -watch|
while read STATUS; do
  case "$STATUS" in
    BLANK*)
      /home/gilson585/sysoff.sh;blanked=1;echo $blanked > blanked
      ;;
    UNBLANK*)
      /home/gilson585/syson.sh;blanked=0;echo $blanked > blanked
      ;;
  esac
done
gilson585
  • 101
  • 3
  • 3
    I'm not even gonna lie, this is quite impressive! Any chance you could share more details about your setup? – Andrew Rhyne Oct 23 '12 at 14:18
  • Yea but there's a lot to it and I'm not so sure here is the place to put it. Maybe I'll post it on the ubuntu forums and link it. – gilson585 Oct 23 '12 at 14:38
  • 3
    You could try controlling this by using an XML file to schedule when and when not to run? The script can prase through that and use it as a control with a logic gate (if) – Andrew Rhyne Oct 23 '12 at 14:40
  • I have begun my how-to article in achieving my setup. http://ubuntuforums.org/showthread.php?t=2075279 tell me more about this XML goodness and how I can utilize it here. – gilson585 Oct 23 '12 at 15:50
  • @andrew-rhyne How-To done http://ubuntuforums.org/showthread.php?t=2075279 – gilson585 Oct 23 '12 at 19:00
  • Okay, what are you going to do? By the way, I do agree that the work is awesome. cron definitely can run scripts at certain times of day, certain days of weeks, a particular holiday, and so forth – Joe Plante Oct 23 '12 at 19:55
  • @joe Cron is awesome but as far as I understand I can only run at boot or on a schedule not both. I need to script the time variable but I'm not sure how. – gilson585 Oct 24 '12 at 12:59
  • 1
    I read the question several times, but i can't understand what exactly you want to do with cron, could you put it in a simple way, "i want x and y", thanks – Mohammad AbuShady Sep 12 '13 at 09:59

1 Answers1

-1

Ah. At the least, you can use two scripts for now. The time setting is a list of weeks/hours/minutes/seconds/etc. You set it up with parameters like

42 * * * * /bin/execute/awesomescript.sh

This would execute something on minute 42 of each hour. This page has an explanation that I would basically be regurgitating: http://kvz.io/blog/2007/07/29/schedule-tasks-on-linux-using-crontab/

There's also scripts like

42 9,12,15 * * * /bin/stuff/awesomestuff.sh

Which will do awesomestuff.sh at 9:42, 12:42, and 15:42

Joe Plante
  • 6,308
  • 2
  • 30
  • 23