LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-24-2022, 04:10 AM   #1
hkjz
Member
 
Registered: Apr 2019
Distribution: MX
Posts: 182

Rep: Reputation: Disabled
[Solved] randomize time of Crontab actions


i have a program that runs in 'crontab -e',
it is set up to run periodically, and looks like this

Code:
*/3 * * * * sudo action_a
how could i randomize its periodicity? How to make the time of change of mac more random?

so in fact i would like to change number '/3' into some random number in range between 1-10

Thanks

Last edited by hkjz; 02-24-2022 at 07:15 AM.
 
Old 02-24-2022, 04:17 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,841

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
do you mean something like this: https://stackoverflow.com/questions/...in-given-hours ?
 
1 members found this post helpful.
Old 02-24-2022, 04:23 AM   #3
hkjz
Member
 
Registered: Apr 2019
Distribution: MX
Posts: 182

Original Poster
Rep: Reputation: Disabled
@pan64 thanks
would that ↓ do?

Code:
0 * * * * perl -le 'sleep rand 600' && *command goes here*
 
Old 02-24-2022, 04:42 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,841

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
just test it. I would rather put it in a shell script, but you can do that way too.
 
Old 02-24-2022, 07:15 AM   #5
hkjz
Member
 
Registered: Apr 2019
Distribution: MX
Posts: 182

Original Poster
Rep: Reputation: Disabled
what worked is

Code:
*/1 * * * * perl -le 'sleep rand 6000' && sudo /usr/local/bin/my_script
 
Old 02-24-2022, 10:38 AM   #6
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,345

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
Just for simplicity sake and so you know
this line is functionally the same
Code:
*/1 * * * * perl -le 'sleep rand 6000' && sudo /usr/local/bin/my_script
as this line
Code:
* * * * * perl -le 'sleep rand 6000' && sudo /usr/local/bin/my_script
 
Old 02-24-2022, 10:48 AM   #7
hkjz
Member
 
Registered: Apr 2019
Distribution: MX
Posts: 182

Original Poster
Rep: Reputation: Disabled
@computersavvy
yup! makes sense
thanks

Last edited by hkjz; 02-24-2022 at 10:49 AM.
 
  


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
Randomize Time for Backgrounds in Ubuntu 11.10 Raliegh Ubuntu 3 02-12-2012 09:49 PM
Is it possible to ask DHCP assign a randomize hostname to client? Reaperhk Linux - Server 1 11-20-2009 08:53 PM
randomize non repeated numbers mystical dervish Programming 10 06-15-2007 04:34 AM
Randomize /etc/motd? lengau Linux - General 4 09-05-2005 11:01 PM
How to randomize Splash Image using Gnome??? thinhla Linux - General 1 07-15-2005 10:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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