Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Say I set my laptop to wake every morning with rtcwake (e.g. echo $(date +%s 'tomorrow 08:00') > /sys/class/rtc/rtc0/wakealarm in a cron job or in /etc/pm/sleep.d/99-set-alarm.sh).

Now, I'd like to run a script from /etc/pm/sleep.d/80-on-rtc-wake.sh only if the laptop was woken by the RTC alarm. Is it possible to check that the laptop was in fact woken by the RTC alarm?

I know I can read /sys/class/rtc/rtc0/wakealarm and it will be empty if the alarm is unset or alarm time has passed, but that leads to a race condition since I want to set the alarm for next morning.

Is there log or something that tells explicitly if the wake was caused by an rtc alarm?

share|improve this question
"but that leads to a race condition since I want to set the alarm for next morning" -- so why not do the check right before adding the next alarm, or a placeholder to make the file non-empty to show that your script was there? Just a thought, I'm not entirely sure my answer makes sense. –  bigbadonk420 Feb 6 '13 at 11:54
Yes, I can (and probably will) do the set-alarm part in 80-on-rtc-wake.sh after reading that /sys/class/rtc/rtc0/wakealarm was empty. But it still doesn't give me assurance that the emptiness is due to an rtc wake (e.g. the computer could have crashed at some point; it's a strong assumption). I can also add a check that time is between 8 and 9 am, but that's even more hacky … –  unhammer Feb 8 '13 at 7:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.