VAR121
VAR121

Reputation: 532

Alarm Script in bash shell

I wanted to write a small script which displays a image or play a song at the particular time. What is the best way(which consumes less RAM) to do that ?

One way I thought is to Recursively query for time using date command and run it through a for loop(checks for hours) within a for loop(checks for minutes) until time reaches the preset time.

Is it the correct approach? are there any other Smart ways of writing it?

Upvotes: 3

Views: 4100

Answers (3)

glenn jackman
glenn jackman

Reputation: 246807

cron is great for running tasks at the same time(s) every day/week/month. If you just want to run a task once at some future time, use at. One great thing about at is that it runs in a copy of your current environment, unlike cron.

Upvotes: 0

Piotr Zierhoffer
Piotr Zierhoffer

Reputation: 5151

Well, I think the best way would be to create a cron job.

With cron you don't have to worry about timing etc, you just create a task. Take a look at its wiki and manual, it's really simple.

You can find an example how to set things up here. It's based on Mint Linux, but should work on any distribution.

Upvotes: 4

Gilles Quénot
Gilles Quénot

Reputation: 185073

In your crontab :

0 7 * * * DISPLAY=:0 display /path/to/image.png; mplayer /path/to/sound.ogg

That will display image.png and play sound.ogg each days at 07 AM.

Adapt it to your needs.

  • display comes with imagemagick
  • mplayer comes with mplayer

Upvotes: 2

Related Questions