Thursday, February 6, 2014

Simple Alarm with Shell Script

In this post, we are going to develop a simple alarm with shell scripts.

To get the time we use date command. To play a sound file we use aplay command-line player. It is also a recorder. Since we are developing an alarm it must control the time continuously so we need an infinite loop. Source codes are given in the following.

Source Codes: 
#!/bin/bash
# Purpose: Demo date command 
# Author: Mustafa Demir -www.eeecoder.blogspot.com-  eeecoder@gmail.com

while :
   do
     echo "Press [CTRL+C] to stop.."
     now=$(date +"%H:%M")
     echo "Current time : $now"

     echo " is current time true ?"

     if [ "$now" == "08:06" ]; then
     echo "Yes!"
     aplay sample.wav
     else
     echo "No!"
     fi

  done

By changing the controlled time and sample.wav you can adjust it as you want.

No comments:

Post a Comment