LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Repeat at random intervals (https://www.linuxquestions.org/questions/linux-newbie-8/repeat-at-random-intervals-665499/)

JWilliamCupp 08-26-2008 08:00 AM

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

TB0ne 08-26-2008 09:04 AM

Quote:

Originally Posted by JWilliamCupp (Post 3260143)
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.

JWilliamCupp 08-26-2008 09:44 AM

Quote:

Originally Posted by TB0ne (Post 3260202)
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

Poetics 08-26-2008 02:02 PM

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.

TB0ne 08-26-2008 02:35 PM

Quote:

Originally Posted by Poetics (Post 3260563)
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...:)


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