LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   RHEL audio script help (https://www.linuxquestions.org/questions/linux-newbie-8/rhel-audio-script-help-4175456779/)

BDole 04-03-2013 09:47 PM

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.

shivaa 04-03-2013 10:41 PM

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

BDole 04-03-2013 11:10 PM

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

shivaa 04-03-2013 11:18 PM

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?

BDole 04-04-2013 10:23 AM

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.

shivaa 04-04-2013 11:09 AM

Quote:

Originally Posted by BDole (Post 4925056)
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.

BDole 04-04-2013 01:28 PM

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.

Habitual 04-04-2013 03:05 PM

Quote:

Originally Posted by BDole (Post 4925056)
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

BDole 04-04-2013 04:11 PM

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?

Habitual 04-04-2013 04:22 PM

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. ;)

BDole 04-04-2013 04:56 PM

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.

Habitual 04-04-2013 05:05 PM

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...

BDole 04-04-2013 05:13 PM

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


All times are GMT -5. The time now is 09:26 AM.