Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

To put it simply, I'm trying to use my computer as an alarm clock. It's slightly old and noisy, so I'd like it to start from power off at a scheduled time and then execute a command, such as playing an MP3 file. I'm running Linux Mint Nadia. How would I go about this?

share|improve this question

3 Answers 3

You can send a magic packet to the computers MAC address. Notice that you need to enable this in your Bios.

Then you can install wakeonlan via apt-get and use the following command to "wake" your system:

wakeonlan 01:02:03:04:05:06

For your concern you need another machine to send this packet. For this there are several wake on lan services you can find via google, where you can set a specific time.

share|improve this answer
2  
Sometimes the magic packet doesn't work. Your system must support Wake on Lan (WOL). en.wikipedia.org/wiki/Wake-on-LAN –  slm Feb 23 at 3:54

From the MythTV's ACPI Wakeup wiki article.

excerpt

Your options

  1. Hardware timer switch - a cheap power switch and a simple cron job to shutdown the machine can do the job
  2. Wake on LAN - have another machine on your network wake your MythTV machine. (See the "Wake on LAN" MythTV HowTo)
  3. Use the real time clock (RTC) - most machines (manufactured in 2000 or later) have the ability to use the RTC for time-controlled wakeup - this option is the subject of this HowTo
share|improve this answer

You are looking for a tool called rtcwake. It allows you to suspend your system and specify a specific wake up time. You can then set up a cronjob to play your song at a specified time.

I found a nice example here:

If I wanted my machine to sleep overnight, wake for a short maintenance, go to sleep again and wake early in the morning, I would have four crons running. The first, to synchronize the OS clock with UTC (via ntp). The second, to synchronize hardware clock with UTC. The third, to put the machine to sleep every evening, using rtcwake and specify the exact moment when it should wake up later. The fourth cron would run a few minutes after the machine wakes and do whatever needs to be done. After all the tasks are complete, it would sleep the machine once more and make it wake up in the morning.

So, in your case, you would set it up to turn the machine on at a couple of minutes before the time you want your alarm to sound and then, set up a cronjob that runs your alarm.

First, suspend your computer and set it to turn on at a specific time, say 9 am. To do this, you need to translate "Tomorrow, 9 am" to UNIX time, seconds since the epoch. You can do this with date:

$ date -d "tomorrow 9 am" +%s
1393228800

Combine that with rtcwake to have your ciomputer sleep now and wake at 9 am tomorrow:

$ rtcwake -m mem -t $(date -d "tomorrow 9 am" +%s)

So, create a crontab to play your mp3 at 9:05 (run crontab -e and paste this line into the file that opens):

05 09 * * * vlc /home/terdon/Music/mysong.mp3

Now, before going to sleep, just turn off the computer with the rtcwake command above and it will automatically turn on next morning at 9 and 5 minutes later will start playing your song.

share|improve this answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.