crontab+mplayer alarm clock


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting crontab+mplayer alarm clock
# 1  
Old 08-05-2012
crontab+mplayer alarm clock

I'm trying to run a alarm.sh using crontab, which play a song as
an alarm at 6.15 am. I'm using amixer so that volume increases by 10% in every loop.

My script is the following.
Code:
SHELL=/bin/bash
PLAYER=/usr/bin/mplayer
SONG=/home/hbar/Music/song.mp3
DISPLAY=:0.0

15 06 * * * /usr/bin/amixer sset Master 10%+ > /dev/null && $PLAYER -loop 5 $SONG > /dev/null 2>&1

However, nothing is happening! If I don't use amixer, song is played in the desired time.

(For testing I was changing the time to a time after 1 minute of the current time, so it's not that I need to wait till 6.15 am.)

Thanks.

Last edited by Franklin52; 08-06-2012 at 03:47 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 08-05-2012
I don't think you can specify variables in cron like that. You can only specify a few things like SHELL.

Also, what's your window manager? GNOME virally hijacks your file permissions via hooks in PAMD and other things, to control who gets permissions to use devices depending on your graphical login. Ergo you may not have permissions to access your sound device until you do a login, no matter what file permissions your sound devices are set to or what groups you belong to. (Or be given permissions without the proper groups or access, for that matter!)

Also, DISPLAY is not needed to play music. Specify -vo null so mplayer doesn't try to open one anyway and die when it can't get into your X context.

Last edited by Corona688; 08-05-2012 at 06:22 PM..
# 3  
Old 08-05-2012
# 4  
Old 08-05-2012
The percent sign (%) is a special character in a crontab command. From the man page

Quote:
The "sixth" field (the rest of the line) specifies the command to be run. The entire command portion of the line, up to a newline or a "%" character, will be executed
by /bin/sh or by the shell specified in the SHELL variable of the cronfile. A "%" character in the command, unless escaped with a backslash (\), will be changed into
newline characters, and all data after the first % will be sent to the command as standard input.
Given this, the command that you are executing isn't what you think it is. Try adding a back slant before the percentage: 10\%

All of Corona688's comments still apply.
# 5  
Old 08-05-2012
@agama.

Putting a baclslash makes it work. Thanks. However, voume does not keep on increasing!

@Corona688

I'm using gnome desktop in ubuntu 12.04. I copied the structure from the internet and many places \dev\null is mentioned. Now, as I just said, it's working but volume is not increasing by 10% !
# 6  
Old 08-05-2012
Quote:
Originally Posted by hbar
@agama.

Putting a baclslash makes it work. Thanks. However, voume does not keep on increasing!

@Corona688

I'm using gnome desktop in ubuntu 12.04. I copied the structure from the internet and many places \dev\null is mentioned. Now, as I just said, it's working but volume is not increasing by 10% !
The way you have your command written, I wouldn't expect the volume to increase. The mixer command is invoked once, and if successful (&&) mplayer is invoked to play the mp3 looping through it 5 times.

If you want to bump the volume with each cycle through the file I would write a small script (alarm.bash or somesuch) and invoke that from cron. The script would look something like this:

Code:
#!/usr/bin/env bash
PLAYER=/usr/bin/mplayer
SONG=/home/hbar/Music/song.mp3

/usr/bin/amixer sset Master 35% >/dev/null 2>&1  # start with a default volume maybe??

for (( i = 0; i < 5; i++ ))
do
   /usr/bin/amixer sset Master 10%+ >/dev/null 2>&1
   $PLAYER -really-quiet -vo null $SONG >/dev/null 2>&1
done

In addition to Carona's suggestion, I'd toss in -really-quiet to cut the overhead of updates directed to /dev/null.

Last edited by agama; 08-05-2012 at 11:25 PM.. Reason: typo/added default volume setting
# 7  
Old 08-05-2012
Quote:
Originally Posted by agama
The way you have your command written, I wouldn't expect the volume to increase. The mixer command is invoked once, and if successful (&&) mplayer is invoked to play the mp3 looping through it 5 times.

If you want to bump the volume with each cycle through the file I would write a small script (alarm.bash or somesuch) and invoke that from cron. The script would look something like this:

Code:
#!/usr/bin/env bash
PLAYER=/usr/bin/mplayer
SONG=/home/hbar/Music/song.mp3

/usr/bin/amixer sset Master 35% >/dev/null 2>&1  # start with a default volume maybe??

for (( i = 0; i < 5; i++ ))
do
   /usr/bin/amixer sset Master 10%+ >/dev/null 2>&1
   $PLAYER -really-quiet -vo null $SONG >/dev/null 2>&1
done

In addition to Carona's suggestion, I'd toss in -really-quiet to cut the overhead of updates directed to /dev/null.
Are you meaning to execute from /etc/crontab? Can't I do it by

crontab <filename>.bash

?
Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Alarm clock error while executing the script

I am executing perl script on Linux machine and the script is running for the last 5 hours and while running the script I had an error message in a single line Alarm Clock and the script got stopped. I havnt scheduled the script.I have executed the script manually. There is no syntax errors in... (1 Reply)
Discussion started by: scriptscript
1 Replies

2. Shell Programming and Scripting

Scripting an alarm

Hi All, I am monitoring batch Processes running in UNIX environment. I use PuTTy to monitor the process running. I have to continuously monitor and look on the screen if some error has come or not. If an error comes FAILURE word is displayed instead of SUCCESS as shown below on the... (2 Replies)
Discussion started by: sampandey31
2 Replies

3. UNIX for Dummies Questions & Answers

alarm

Hello I have a server HP ES40 with unix 5.1B, and if i open from Start-Programs-IN Tools-GUI/pfmalarm/Alarm-start monitoring , I receive this error message "IOR : STRING IS TOO LONG ! MAXIMUM SIZE = 1024" Anybody heard about this error? Thanks Alin (0 Replies)
Discussion started by: tomaalin
0 Replies
Login or Register to Ask a Question