LinuxQuestions.org
Review your favorite Linux distribution.
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


Closed Thread
  Search this Thread
Old 03-20-2010, 04:57 AM   #1
anurupr
Member
 
Registered: Mar 2010
Posts: 71

Rep: Reputation: 16
i need to constantly run a script in the background


i need to run a script which checks if a cd is mounted or not
 
Old 03-20-2010, 04:59 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
right, did you wnat to ask a question about doing that??

Assuming you want to know how to, I'd say you don't need to run it constantly, just frequently, in qhich case a cronjob is the order of the day.
 
Old 03-20-2010, 05:04 AM   #3
Maligree
Member
 
Registered: Mar 2008
Distribution: Gentoo, CentOS, Fedora, Arch
Posts: 231
Blog Entries: 1

Rep: Reputation: 42
duplicate of this thread
 
Old 03-20-2010, 05:16 AM   #4
sd||
Member
 
Registered: Oct 2009
Distribution: Arch Linux
Posts: 89

Rep: Reputation: 18
you can do this using cron jobs


edit /etc/crontab

know more about this
Quote:
man cron
man crontab

Last edited by sd||; 03-20-2010 at 05:18 AM.
 
Old 03-20-2010, 05:23 AM   #5
nonamenobody
Member
 
Registered: Oct 2002
Posts: 138

Rep: Reputation: 22
Quote:
Originally Posted by anurupr View Post
i need to run a script which checks if a cd is mounted or not
It would be helpful to know what you are trying to achieve (i.e. why are you checking if it is mounted), as there may be a better solution.

That said, to do what you ask, simply put the code that you want to repeat in a 'while true' loop. Looping continuously without a break might be quite resource intensive, so you may do better to stick a sleep command into the loop, so that your check runs every x seconds/minutes. If you only want to perform the check once per minute or less, then cron may be a better solution.

The best solution may be to use udev rules so that a script is run once when a CD is mount and/or unmounted - see http://www.reactivated.net/writing_u...l#external-run

Oh, and to put the script in the background run it with an ampersand after it (&) - though it will quit when it's parent process is killed, e.g. if you close the terminal that issued the command. If you want to keep it running permanently you need to send it the NOHUP signal using kill. You may even want to make a daemon that runs on start up - by creating the relevant scripts in /etc/init.d/ and /etc/rc.d/...
 
Old 03-20-2010, 05:29 AM   #6
nonamenobody
Member
 
Registered: Oct 2002
Posts: 138

Rep: Reputation: 22
Quote:
Originally Posted by Maligree View Post
duplicate of this thread
Not exactly a duplicate, although his titles are very similar. In the first thread he didn't even know how to check if the CD was mounted, now wants to do the next bit. It is more a continuation than a duplicate - he probably should have used the same thread though.
 
Old 03-20-2010, 08:00 AM   #7
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
Hi,

Quote:
Originally Posted by anurupr View Post
i need to run a script which checks if a cd is mounted or not
So you've shown us your need! What's your deed?

We will aid you when you help yourself to a solution. Provide us with what you have attempted and then maybe someone will be able to assist. Such an open ended query without details is rather hard to aid.

Just a few links to aid you to gaining some understanding;

Linux Documentation Project
Rute Tutorial & Exposition
Linux Command Guide
Utimate Linux Newbie Guide
LinuxSelfHelp
Getting Started with Linux
Bash Reference Manual
Advanced Bash-Scripting Guide
Linux Home Networking


The above links and others can be found at 'Slackware-Links'. More than just SlackwareŽ links!
 
Old 03-20-2010, 04:15 PM   #8
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Please post your thread in only one forum. Posting a single thread in the most relevant forum will make it easier for members to help you and will keep the discussion in one place. This thread is being closed because it is a duplicate.


http://www.linuxquestions.org/questi...g-bash-796643/
 
  


Closed Thread



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
trying to run a script in the background redirect the output to a file jdwalk Linux - Newbie 7 10-30-2019 10:17 AM
run script in background MikeQ Linux - Newbie 2 09-11-2009 06:21 PM
What is the easiest way to run a shell script in the background on 10 servers? abefroman Linux - Software 3 03-12-2008 09:24 AM
How to run a shell script in a background? anandv_1234 Linux - Newbie 3 12-23-2007 03:03 AM
how do i get a shell script to run in the background? tjyorkshire Programming 4 07-06-2007 02:28 AM

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

All times are GMT -5. The time now is 04:38 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