LinuxQuestions.org
Review your favorite Linux distribution.
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 11-27-2013, 02:24 PM   #1
LightSeeker
Member
 
Registered: Nov 2007
Distribution: Manjaro, Win7
Posts: 41

Rep: Reputation: 0
How to make a bash script run as a daemon?


Hi,

I've put together a little script that modifies my keyboard layout somewhat (using xmodmap). Until now, everything was fine, I just put that script into my startup programs (I'm using XFCE) and it automatically changed the configuration to my liking. Now, however, I've bought an external keyboard and as a consequence, if I (un)plug while the computer is already booted, the settings won't apply automatically, but I have to run the script manually.

Now I want to modify my script so that it will check whether or not a keyboard has been plugged and which would run the changes if that was indeed the case. The thing is, that in order for this to work, the script would have to constantly monitor whether or not the device is plugged in. So I'm guessing it would have to run as a daemon? Is there a way to do that?

I've looked around and I've seen a program called daemonize (http://software.clapper.org/daemonize/). Would that be a good solution? Or should I manually insert a script (if that is possible at all) into the aprorpriate /etc subfolder that handles services that are run at boot?
 
Old 11-27-2013, 02:54 PM   #2
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,977
Blog Entries: 1

Rep: Reputation: 209Reputation: 209Reputation: 209
What system are you using?

Try the "daemon" command.

On a RH box (RHEL/CentOS) you can do this

Code:
root@host# . /etc/init.d/functions
root@host# daemon --help
 
Old 11-27-2013, 02:57 PM   #3
LightSeeker
Member
 
Registered: Nov 2007
Distribution: Manjaro, Win7
Posts: 41

Original Poster
Rep: Reputation: 0
Right now I am running Xubuntu, but I will be migrating to Arch in a week or two (Ubuntu keeps giving me some issues).

p.s.:I don't have the "function" in etc/initd.d

Last edited by LightSeeker; 11-27-2013 at 03:05 PM.
 
Old 11-27-2013, 04:05 PM   #4
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 4,466
Blog Entries: 6

Rep: Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408
Quote:
Originally Posted by LightSeeker View Post
I've looked around and I've seen a program called daemonize (http://software.clapper.org/daemonize/). Would that be a good solution? Or should I manually insert a script (if that is possible at all) into the aprorpriate /etc subfolder that handles services that are run at boot?
Not sure about your particular usage, but I use the daemonize from your link and it works quite well under Slackware.

Building it should not be a problem as it has no special dependencies that I recall.

There seem to be no download tarballs on the repo so get it by git clone.

Last edited by astrogeek; 11-27-2013 at 04:08 PM.
 
Old 11-29-2013, 01:29 PM   #5
LightSeeker
Member
 
Registered: Nov 2007
Distribution: Manjaro, Win7
Posts: 41

Original Poster
Rep: Reputation: 0
Okay, thanks for all the suggestions, I'll modify the script to check for connected devices and then try the daemonize program solution.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Run bash script as a daemon. gajananh999 Linux - Newbie 13 10-30-2012 05:47 AM
[SOLVED] Make a bash script into a daemon DuskFall Linux - Newbie 6 08-08-2011 03:46 AM
Run my bash script as a daemon. jaimese Linux - Newbie 12 02-10-2011 03:28 PM
Bash script to verify the daemon is working if not, start the daemon kishoreru Linux - Newbie 7 09-23-2009 04:29 AM
A better way to make a bash script run on boot helptonewbie Linux - General 6 09-13-2006 06:59 PM

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

All times are GMT -5. The time now is 02:46 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration