LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-03-2013, 09:47 PM   #1
BDole
LQ Newbie
 
Registered: Apr 2013
Posts: 7

Rep: Reputation: Disabled
RHEL audio script help


As per the forum I'm a noob, looking for help writing a script that will play an audio file when a drive is mounted and another when a drive is unmounted.
 
Old 04-03-2013, 10:41 PM   #2
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Provide little more info. like, your linux distrobituion, which music player you're using, and also what you've tried so far..

For instance, you can play a file in vlc player like:
Code:
~$ vlc song.mp3

Last edited by shivaa; 04-03-2013 at 10:43 PM. Reason: Command added
 
Old 04-03-2013, 11:10 PM   #3
BDole
LQ Newbie
 
Registered: Apr 2013
Posts: 7

Original Poster
Rep: Reputation: Disabled
It's RHEL 6, looking to use all native functions.. so i was thinking of using a .wav & play. Really need help with the alerting on drive mounts and unmounts part
 
Old 04-03-2013, 11:18 PM   #4
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
As said, explain it in little more details.. which music player you're using, what you've tried so far and where you're stuck?
 
Old 04-04-2013, 10:23 AM   #5
BDole
LQ Newbie
 
Registered: Apr 2013
Posts: 7

Original Poster
Rep: Reputation: Disabled
Again, looking to use all native functions.. sox is installed so I plan on using the play command.. where I need help is the mount detection scripting.

I really don't know where to start there, so I can't tell you what I've tried wrt that.
 
Old 04-04-2013, 11:09 AM   #6
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Quote:
Originally Posted by BDole View Post
Again, looking to use all native functions.. sox is installed so I plan on using the play command.. where I need help is the mount detection scripting.

I really don't know where to start there, so I can't tell you what I've tried wrt that.
Ok. Can you explain where you're stuck or what exactly you've done? Are you mounting any external device and want a script to detect that device and if that device contains any music files, then play it?

Without complete scenario, it will not be easy to suggest anything, and all it will be just a guess work. Hope this makes some sense now.

Last edited by shivaa; 04-04-2013 at 11:10 AM.
 
Old 04-04-2013, 01:28 PM   #7
BDole
LQ Newbie
 
Registered: Apr 2013
Posts: 7

Original Poster
Rep: Reputation: Disabled
Ok sorry I'll try to be more descriptive:

What I want to do is something similar to the windows world, where when a device is connected or disconnected a sound is played, one sound for device connections, one for disconnections. The sound files (.wav) would be present on the host filesystem, not the external drives. I'd like this notification to play regardless of the type of drive mounted, or where it was mounted from.

I know how to play the sound files using "play", where I'm stuck is where to begin with detecting drives being mounted. I'd like the script to be independent of any actions I'm taking.. so iow I'm not looking for something that will both mount a drive & play a file, I'm looking for distinct logic that will detect the mounts and unmounts and play the sound.. hope that's better.

---------- Post added 04-04-13 at 02:29 PM ----------

And sorry but I haven't done anything to give you an example thus far, I really don't even know where to start.
 
Old 04-04-2013, 03:05 PM   #8
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by BDole View Post
where I need help is the mount detection scripting.
Code:
#!/bin/bash
if [[ -d /mnt/cdrom ]]; then 
    /path/to/sox_script.sh 
else 
    mount command here
    /path/to/sox_script.sh
fi
/mnt/cdrom will be different depending on OS.

if [[ -d /mnt/cdrom ]] should evaluate to True, if /mnt/cdrom exists.
-d is for testing if the file at /mnt/cdrom is a directory.

You can test this logic thusly:
On your host, in terminal >
Code:
sudo find /mnt -type d
Pick ONE! for the next line...
I'm assuming you have a cdrom, so let's test the code for success with

Code:
if [[ -d /mnt/cdrom ]]; then echo "We have a cdrom" ; else echo "Bust out the 8-Track Tapes"; fi
NOW, let's change it up (we are simulating a disconnected media device)
Code:
if [[ -d /mnt/external_drive ]]; then echo "We have a cdrom" ; else echo "Bust out the 8-Track Tapes"; fi
I hope this helps you out.

Smarter people than I may have more to say on this subject.

Here's some references:
http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
http://www.tldp.org/LDP/Bash-Beginne...tml/index.html
http://tldp.org/HOWTO/Bash-Prompt-HOWTO/
http://www.gnu.org/software/bash/man...ode/index.html
http://www.grymoire.com/Unix/Sh.html
http://www.grymoire.com/Unix/Sed.html
http://tldp.org/LDP/abs/abs-guide.pdf
http://www.tldp.org/LDP/abs/html/
http://mywiki.wooledge.org/BashFAQ
http://mywiki.wooledge.org/BashPitfalls
http://rute.2038bug.com/index.html.gz
http://mylinuxbook.com/linux-shell-environment/
http://www.subsignal.org/doc/AliensB...0Of%20Contents
http://www.rigacci.org/docs/biblio/o...TLCL-09.12.pdf
http://www.linuxhomenetworking.com/
http://mylinuxbook.com/bash-shell-scripting-part-i/
http://mylinuxbook.com/bash-shell-scripting-2/
https://help.ubuntu.com/community/CommandLineResources
http://linuxcommand.org/lc3_learning_the_shell.php
http://unixhelp.ed.ac.uk/

and you can search all of those at
http://www.google.com/cse/home?cx=01...1bdfg5ga&hl=en

Last edited by Habitual; 04-04-2013 at 03:08 PM.
 
Old 04-04-2013, 04:11 PM   #9
BDole
LQ Newbie
 
Registered: Apr 2013
Posts: 7

Original Poster
Rep: Reputation: Disabled
Thanks for taking the time to help me out, that looks like a good starting point and i think i would easily be able to write a script based off you guidance in this regard; however my concern is this:

The logic you provided as example depends on testing a condition on the mount point.. so I would need to constantly test the condition and thus it would constantly alert one way or another.. is there a better way to do it such that i'm detecting a change in state on the mount point?
 
Old 04-04-2013, 04:22 PM   #10
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
I would need to constantly test the condition and thus it would constantly alert one way or another...
UDev rules I think can solve this requirement.
But I have to ask why you think there's a need to check it "constantly"?

The answer will dictate the code.
 
Old 04-04-2013, 04:56 PM   #11
BDole
LQ Newbie
 
Registered: Apr 2013
Posts: 7

Original Poster
Rep: Reputation: Disabled
Sorry, perhaps I'm missing something.. but how else would you be able to tell when the change happens in real time? say I've got other users on my system who are logged in and mount drives.. I want to know when that happens and if something is being mounted or unmounted.
 
Old 04-04-2013, 05:05 PM   #12
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
I believe the UDev rule will accommodate this request and I have no experience in that arena.
And since I have no experience in that area, I'd be poorly guessing at what that process does
to make it work.

Sorry, someone else will be along to help...
 
Old 04-04-2013, 05:13 PM   #13
BDole
LQ Newbie
 
Registered: Apr 2013
Posts: 7

Original Poster
Rep: Reputation: Disabled
No problem, I still learned something new from what you posted and I appreciate that I just wanted to make sure I understood your last statement and wasn't missing something obvious there.

Cheers
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
No audio on RHEL 4.5 on a Dell Precision 380 alibabs Linux - Newbie 1 03-08-2013 03:49 AM
i cannot play my audio/video files in RHEL 5 jain_Abraham Linux - Newbie 8 03-04-2011 03:15 PM
RHEL 4, surepos 563 lockup, initializing hardware storage network audio dsieme01 Linux - Hardware 4 04-01-2008 01:18 AM
sigmatel high defination audio not working on RHEL 4.0 sachin_malik Linux - Hardware 0 08-03-2007 11:50 AM
RHEL 4 not detecting my Audio Driver md.samim Linux - Enterprise 0 04-18-2006 03:21 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration