LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-08-2012, 03:47 PM   #1
makowka
Member
 
Registered: Feb 2007
Posts: 42

Rep: Reputation: 8
Demonized bash script


Hello

I have a problem writing a shell script, that is supposed to run as a demon. Its aim is to check for a device file and then to execute another script, that is, it checks, if the exaile music player creates a jack device, then it executes the script for establishing jack connections exaile->jamin.

It looks like this:

Code:
#!/bin/sh

while true
do
if [ -f /dev/shm/sem.jack_sem.1000_default_exaile.py ]
then
    /usr/local/bin/jack_snapshot restore 2
    break
else
continue
fi
done
As you can see, I have applied an endless loop, in order to work constantly in the background. The problem is, that I want the "/usr/local/bin/jack_snapshot restore 2" to be executed only once. The script is supposed to do the following:

Check if the device "/dev/shm/sem.jack_sem.1000_default_exaile.py" is present, then create the jack connections. If exaile isn't playing, the device file is not present. Anyone has an idea, how to accomplish this?
 
Old 09-08-2012, 08:28 PM   #2
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 3,340

Rep: Reputation: Disabled
Do I understand you correctly in that you want the script to execute the command in question whenever the device file is created, but only once each time?

I guess you could enter a second (inner) loop once the device file is found, one that loops until the device file disappears again.

Are you sure this isn't something a udev script would be better suited for?
 
1 members found this post helpful.
Old 09-09-2012, 07:58 AM   #3
makowka
Member
 
Registered: Feb 2007
Posts: 42

Original Poster
Rep: Reputation: 8
Yes, you are correct, the command is to be executed only once, each time the device file is created.
Can you tell me, how to accomplish that with udev? I am not sure, it it is possible with nested loops, since the first loop always has to be a while-true loop, which can be stopped only by the break command - which would also terminate the script, and that I don't want to happen.
 
Old 09-09-2012, 08:21 AM   #4
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
Moderator Response

Moved: This thread is more suitable in <Programming> and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 09-09-2012, 11:09 AM   #5
makowka
Member
 
Registered: Feb 2007
Posts: 42

Original Poster
Rep: Reputation: 8
Actually, I managed to do my task wit the iwatch command. I have put the following in .profile:

Code:
iwatch -v -c /usr/local/bin/exaile_detect -e create -t sem.jack_sem.1000_default_exaile.py /dev/shm/ &
Problem solved! Thank you for the answers.
 
  


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
How to get some bash scripts into a simple bash script with some echo and if statement. y0_gesh Programming 3 03-01-2012 09:46 AM
[SOLVED] Run multiple bash and php scripts from a bash script charu Programming 5 07-26-2011 02:40 AM
Variables and Mkvextract in a bash script and a good resource for bash help? gohmifune Linux - General 9 04-13-2011 08:37 AM
SSH connection from BASH script stops further BASH script commands tardis1 Linux - Newbie 3 12-06-2010 08:56 AM
[SOLVED] Using a long Bash command including single quotes and pipes in a Bash script antcore Linux - General 9 07-22-2009 11:10 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:48 AM.

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