How to schedule Linux to mute speaker volume overnight

Here’s a simple method of automatically muting your volume overnight and resetting it in the morning. This is especially good for those who use softphones, skype or an IM client that have sound alerts output to speakers.

We are going to use three command line tools for this: aumix, which and cron. We are also only going to set things up so the commands are run under the user account, rather than as root as cron used incorrectly can open up some security issues.

so, to get started try and run:

:~$ aumix

and if it’s not there, try

:~$ sudo apt-get install aumix

for Debian / Ubuntu or

:~$ yum install aumix

for Redhat / Centos / Fedora

Now that we have aumix installed, we want to find out the path to the executable as Cron doesn’t always use our environmental variables to find executables on our path. So type:

:~$ which aumix

We can see it’s in /usr/bin/aumix

So, kick-off your music player and try playing some music or other audio then run the following commands:

:~$ aumix -v 0


:~$ aumix -v 100

The first command should have dropped your volume down to 0% and the second command should have taken it back to 100%. Now that we have that working, let’s add it to cron. For myself, I don’t want to be disturbed between 11pm and 7am, so following cron’s options, we have

minute-hour-day-month-weekday-command – and we use 24 hour format. An asterisk means run at every instance of that time period, so:
* * * * * would mean every minute of every day, every month and
0 0 * * * would mean at midnight every day.

For myself, I want the 23rd hour of every day, every month for the volume to be set down and I want the 7th hour of every day for the volume to be returned to 90%. So we add this to our crontab:

0 23 * * * /usr/bin/aumix -v 0
00 07 * * * /usr/bin/aumix -v 90

To do so as a user, we use:

:~$ crontab -e

Now if your default editor is vim / vi and you have never used it before, you will need to learn a little vi before we get started. When the editor opens, type to enter insert mode allowing you to copy and paste the above code and modify for your needs, when you are finished editing, press esc then VV to save the file and exit.

If the above vi / vim is too difficult, then you can make nano your default editor (if it’s not already)

:~$ EDITOR=/usr/bin/nano

and then run

:~$ crontab -e

Nano is a simplistic editor with the basic instructions displayed at the bottom of the screen.

So, there you have the very basics of Cron administration – ie: the Task Scheduler of Linux and how to adjust your volume via the command line.

If you are looking for a GUI tool for Cron Administration, look no further than gnome-schedule:

:~$ sudo apt-get install gnome-schedule

here’s our beloved screenshot:

for raising and lowering the volume.

Technorati Tags: , , ,

Published by salubrium

I am a Systems Administrator based in Sydney, Australia with some hugely varied interests: Topics covered are Virtualization, Web Hosting, Remote Desktop, Security and Backups, PHP, Python, MVC Frameworks, SEO

Leave a comment

Your email address will not be published. Required fields are marked *