LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 08-26-2008, 08:00 AM   #1
JWilliamCupp
Member
 
Registered: Jul 2005
Location: Indiana, U.S.A.
Distribution: Fedora
Posts: 57

Rep: Reputation: 15
Repeat at random intervals


I'm trying to come up with a way to repeat things at random intervals. I think I need to use "at" and call an executable file that terminates by placing a new "at" command.

I have a collection of "cute" sounds and I want my box to interesting little noises at odd, infrequent intervals.

This is what I've come up with so far -- creating a file something like this:

- - - - - - - - - - - - - - -
# filename: cute_sounds.txt
# repeats a selected sound at random interval
# as shown, repeats from 1 to 30 days from "now"

# replace "some_cute_sound_file.wav" with the name of the
# sound file to be played

play some_cute_sound_file.wav

at now * (1 + (int) (30.0 * (rand() / (RAND_MAX + 1.0)))) days cute_sounds.txt

- - - - - - - - - - - - - - -

Has anyone done something like this before? Any ideas or tips to help me along the way?

- Bill
 
Old 08-26-2008, 09:04 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by JWilliamCupp View Post
I'm trying to come up with a way to repeat things at random intervals. I think I need to use "at" and call an executable file that terminates by placing a new "at" command.

I have a collection of "cute" sounds and I want my box to interesting little noises at odd, infrequent intervals.

This is what I've come up with so far -- creating a file something like this:

- - - - - - - - - - - - - - -
# filename: cute_sounds.txt
# repeats a selected sound at random interval
# as shown, repeats from 1 to 30 days from "now"

# replace "some_cute_sound_file.wav" with the name of the
# sound file to be played

play some_cute_sound_file.wav

at now * (1 + (int) (30.0 * (rand() / (RAND_MAX + 1.0)))) days cute_sounds.txt

- - - - - - - - - - - - - - -

Has anyone done something like this before? Any ideas or tips to help me along the way?

- Bill
Instead of an at job, why not just make the script sleep for some interval? When you run it, run it with "nohup <script name> > /dev/null 2>&1&" That will background it, with it's own process, so even if you log out, it'll continue to run.
 
Old 08-26-2008, 09:44 AM   #3
JWilliamCupp
Member
 
Registered: Jul 2005
Location: Indiana, U.S.A.
Distribution: Fedora
Posts: 57

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by TB0ne View Post
When you run it, run it with "nohup <script name> > /dev/null 2>&1&" That will background it, with it's own process, so even if you log out, it'll continue to run.
Will this last through a reboot? I'm thinking to have the sound(s) repeat at infrequent intervals for the indefinite future. Rebooting would terminate any background process, but I think an at command will run at the scheduled time, even after a reboot.

Can at commands be filed to run after logout? Can they be set to run after login if the set time was missed due to the user being logged out? (Would it be useful to have the command entered as root?)


- Bill
 
Old 08-26-2008, 02:02 PM   #4
Poetics
Senior Member
 
Registered: Jun 2003
Location: California
Distribution: Slackware
Posts: 1,181

Rep: Reputation: 49
If you're worried about the command running after reboot, add it to your startup scripts! I don't know Fedora's methodology off the top of my head, but I'm pretty sure they still use rc.local -- this is where you can put custom startup scripts; anything therein is run just before the first login prompt is displayed.
 
Old 08-26-2008, 02:35 PM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,634

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by Poetics View Post
If you're worried about the command running after reboot, add it to your startup scripts! I don't know Fedora's methodology off the top of my head, but I'm pretty sure they still use rc.local -- this is where you can put custom startup scripts; anything therein is run just before the first login prompt is displayed.
Beat me to it...
 
  


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
NOOB - DNS latency on FC6 - seems to "hang" eth0 at random intervals? How to fix? rylan76 Linux - Newbie 4 12-22-2006 12:34 PM
NOOB - DNS latency on FC6 - seems to "hang" eth0 at random intervals? How to fix? rylan76 Red Hat 1 12-22-2006 05:07 AM
NOOB - DNS latency on FC6 - seems to "hang" eth0 at random intervals? How to fix? rylan76 Linux - Networking 1 12-22-2006 04:45 AM

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

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