Page 1 of 2

Cron jobs

Posted: 24 May 2013, 18:32
by NBJess
I'm looking to set up some customized kiosks to access the catalog in my library and am super psyched to find Porteus, but one of the things that I'd really like is to set a cron job to shutdown the computers when the library is about to close. I know just enough about Linux to be a danger to myself, so I'm not sure what the best way is to make this happen. I'd like to add the following settings, but I just don't know where to make these changes.

59 20 * * 1-4 shutdown -h
59 17 * * 5-6 shutdown -h

Any suggestions?

Thanks in advance.

Re: Cron jobs

Posted: 24 May 2013, 21:35
by fanthom
hello NBJess,

cron is missing in Kiosk but we can use a simple bash script for this task. please save this code as /porteus/rootcopy/etc/rc.d/rc.local, make 'rc.local' executable and create new Kiosk ISO with /porteus/make_iso.sh script.

here is the code:

Code: Select all

#!/bin/sh

(
if date +%a | egrep 'Mon|Tue|Wed|Thu'; then
    min=$(echo $((59-`date +%M`)))
    hr=$(echo $(echo $((20-`date +%H`)))*60)
    mins_total=$(echo $(($min+$hr)))
    sleep "$mins_total"m 2>/dev/null && poweroff
else
    min=$(echo $((59-`date +%M`)))
    hr=$(echo $(echo $((17-`date +%H`)))*60)
    mins_total=$(echo $(($min+$hr)))
    sleep "$mins_total"m 2>/dev/null && poweroff
fi
) &
explanation:
this function counts number of minutes which left to the deadline then invokes 'sleep' command before shutting the PC down.
deadline is set to 20:59 for Mon-Thu and to 17:59 for the rest of days.
let me know if the syntax is a trouble for you.

btw: this code will work with kiosk-2.0.3 which is planned to go live on Monday (had to recompile busybox to add 'date' command support).

Re: Cron jobs

Posted: 31 May 2013, 19:01
by NBJess
Hi fanthom,

Sorry for the delay. I had some fires to put out at work this week.

Thanks for the bash script. I tried it with the newest version, v.2.0.3, and unfortunately, when I booted up the kiosk, it would only load the desktop-- Firefox never loaded.
The same customizations without the script booted up just fine. Any suggestions?

Thanks.

Re: Cron jobs

Posted: 31 May 2013, 21:33
by fanthom
just checked and script works perfectly for me with 2.0.3
did you do any other customization to the ISO? please double check or upload your build if possible.

you can send me a link to fanthom@porteus.org and i'll have a quick look on it.

Re: Cron jobs

Posted: 06 Sep 2013, 06:43
by sanzi
I have got a similar problem. On Monday I switch the PC with Porteus Kiosk Edition manual. On 17:00 I want to go the computer to hibernate, and wake up from hibernate next day morning at 08:00. This method should work every day, expect friday, when 17:00 shutdown. I would like a PC, which one follow this commands:
Monday 08:00 Power on manual 17:00 Go hibernate automatically (with keyboard or mouse can't wake up, and the computer consume minimum electiricy power)
Tuesday 08:00 Wake up from hibernate 17:00 Go hibernate automatically
Wednesday 08:00 Wake up from hibernate 17:00 Go hibernate automatically
Thursday 08:00 Wake up from hibernate 17:00 Go hibernate automatically
Fiday 08:00 Wake up from hibernate 17:00 Shut down completely automatically

Thank so much the answer and the help!

Re: Cron jobs

Posted: 06 Sep 2013, 08:49
by fanthom
i dont think you'll be able to wake up automatically from hibernation as CPU remains inactive. the simplest solution is to shut down on certain hour (like in my script above) and power on manually next day.

if you really want everything done automatically then you have to choose other power state where CPU/memory are active (processes are running) but this solution wont be energy efficient. you probably will be interested in 'freeze' and 'standby' as they leave CPU powered on but you need to do some tests first (and check if your motherboard/CPU supports them):
https://www.kernel.org/doc/Documentatio ... states.txt

Re: Cron jobs

Posted: 08 Sep 2013, 21:15
by sanzi
I think the freeze is good for me. Can't wake up with mouse or keyboard. Consume this state less power than standby? My computer support freeze. What is the next step? Please help me, I don't understand the code in the second comment. Thanks!
I need something like this:

String day:=getDay();
if (day==Monday) than {
16:00 freeze on;
} else if (day==Thuesday) {
08:00 freeze off;
16:00 freeze on;
} else if (day==Wednesday) {
08:00 freeze off;
16:00 freeze on;
} else if (day==Thuersday) {
08:00 freeze off;
16:00 freeze on;
} else if (day==Friday) {
08:00 freeze off;
16:00 power off
}

Re: Cron jobs

Posted: 09 Sep 2013, 15:04
by fanthom
@sanzi

good news - i have found that we can use rtc for waking up alert which let us do a full suspend to memory (offers much better power savings than freeze or standby states).

please save this script as /porteus/rootcopy/etc/rc.d/rc.local and make executable:

Code: Select all

#!/bin/sh

(
while [ 1 ]; do

suspend_kiosk() {
echo `date '+%s' -d "+ 16 hours"` > /sys/class/rtc/rtc0/wakealarm
echo mem >/sys/power/state
}

if date +%a | egrep -q 'Mon|Tue|Wed|Thu'; then
    min=$(echo $((59-`date +%M`)))
    hr=$(echo $(echo $((15-`date +%H`)))*60)
    mins_total=$(echo $(($min+$hr)))
    sleep "$mins_total"m 2>/dev/null && suspend_kiosk || exit
elif date +%a | grep -q Fri; then
    min=$(echo $((59-`date +%M`)))
    hr=$(echo $(echo $((15-`date +%H`)))*60)
    mins_total=$(echo $(($min+$hr)))
    sleep "$mins_total"m 2>/dev/null && poweroff || exit
fi

done
) &
let me know if it worked for you.

Re: Cron jobs

Posted: 10 Sep 2013, 07:02
by sanzi
Thank you so much! :beer:

I will try today, but I have got one question yet. Where can I modify the times? When go down, and when wake up? Please explain this part of the code. Thanks!

Re: Cron jobs

Posted: 10 Sep 2013, 08:57
by fanthom
in this line we are programming rtc to wake up after 16 hours:

Code: Select all

echo `date '+%s' -d "+ 16 hours"` > /sys/class/rtc/rtc0/wakealarm
this line counts how many minutes left before PC goes down:

Code: Select all

min=$(echo $((59-`date +%M`)))
this line counts how many hours left before PC goes down (hours are converted to minutes):

Code: Select all

hr=$(echo $(echo $((15-`date +%H`)))*60)
example for going down at 18:00 and waking up at 09:00 next day would be:

Code: Select all

#!/bin/sh

(
while [ 1 ]; do

suspend_kiosk() {
echo `date '+%s' -d "+ 15 hours"` > /sys/class/rtc/rtc0/wakealarm
echo mem >/sys/power/state
}

if date +%a | egrep -q 'Mon|Tue|Wed|Thu'; then
    min=$(echo $((59-`date +%M`)))
    hr=$(echo $(echo $((17-`date +%H`)))*60)
    mins_total=$(echo $(($min+$hr)))
    sleep "$mins_total"m 2>/dev/null && suspend_kiosk || exit
elif date +%a | grep -q Fri; then
    min=$(echo $((59-`date +%M`)))
    hr=$(echo $(echo $((17-`date +%H`)))*60)
    mins_total=$(echo $(($min+$hr)))
    sleep "$mins_total"m 2>/dev/null && poweroff || exit
fi

done
) &

Re: Cron jobs

Posted: 11 Sep 2013, 09:52
by sanzi
The code is work, but I have got an other problem. I mount my isohybrid file and copy all of it to a dir (boot and porteus directories). I copy the rc.local to the right place and made executable. I try to make a new iso with the new file, so run the make_iso.sh , but it not work:
./make_is.sh: line 28: /tmp/selfgz394721510/bin/mkisofs: No such file or directory

I try it on Porteus Desktop Portalbe version, boot from CD.

Re: Cron jobs

Posted: 11 Sep 2013, 10:17
by fanthom
you should start another thread for non working 'make_iso.sh'.
anyway - here is the solution: use 'make_iso.sh-org' instead.

Re: Cron jobs

Posted: 11 Sep 2013, 10:51
by sanzi
Thanks, this is work. What is the different?

Update: The code, what you wrote to me works perfectly on Porteus Desktop, but on Kiosk don't. The computer don't go sleep. A make a new file with this content:

Code: Select all

#!/bin/sh

(
while [ 1 ]; do

sleep 5m
echo `date '+%s' -d "+ 2 minutes"` > /sys/class/rtc/rtc0/wakealarm
echo mem >/sys/power/state

done
) &
The computer wait 5 minutes, OK, go to sleep OK, but not wake up after 2 minutes. What is the problem?
I run the Desktop version from CD, and the Kiosk version from HDD.

update: With this code the Desktop version wake up.

Re: Cron jobs

Posted: 11 Sep 2013, 12:18
by fanthom
just checked and kiosk kernel has no support for /dev/rtc compiled in - will add this option to next kiosk release.
for now please use the kernel from 32bit Porteus Desktop edition. please copy /boot/syslinux/vmlinuz and /porteus/base/000-kernel.xzm to the kiosk ISO and should be ok.

Re: Cron jobs

Posted: 11 Sep 2013, 14:02
by sanzi
In my Kiosk iso the /boot/syslinux dir is not exist, so I made it with chmod +x . I copy the vmlinuz here, and the 000-kernel.xzm next to the other xzm modul. Make new iso, convert isohybrid and copy to hdd. The Kiosk boot corretly, but nothing happend in the current time, don't go sleep, so it not work.