Pak Jiddat

Read: In the name of thy Lord Who createth, Createth man from a clot. Read: And thy Lord is the Most Bounteous, Who teacheth by the pen, Teacheth man that which he knew not. Nay, but verily man is rebellious That he thinketh himself independent!. Lo! unto thy Lord is the return. (Sura Alalaq 96:8)

Running Cron jobs at random intervals

Created On: 18 Dec, 2018: 18:53:59 - Tags : command line tools | server management

Url: https://stackoverflow.com/a/16289693/4508593

To run a Cron Job at random intervals we need to prefix the Cron Job command with the sleep bash command. For example to run a Cron Job every 5 to 7 hours at random intervals, we can use the following:


0 */5 * * * sleep $[RANDOM\%120]m; path-to-script

In the above code, the '%' has to be escaped. The code: $[RANDOM\%120] generates a random number between 0 and 120. This is the number of minutes that script will pause

The script will run at the times: 05:00+(rand(0, 120)), 10:00+(rand(0, 120)), 15:00+(rand(0, 120)), 20:00+(rand(0, 120)) and 00:00+(rand(0, 120))


Related Articles

  1. Checking hard disk for bad blocks
  2. Generating free SSL certificate from LetsEncrypt on localhost
  3. Running Plesk auto reapir
  4. Viewing package information using yum history command
  5. Deleting files older than 1 year using Linux command line tools
  6. Deleting empty folders recursively using Linux command line tools
  7. Setting file permissions with rsync
  8. Using Rsync over custom SSH port
  9. Finding name server records for domains using Dig
  10. Backing up and restoring LXD containers
  11. Ignoring errors during MySQL import
  12. Resizing Linux root partitions without unmount on Google Cloud
  13. Running multiple versions of mailx command
  14. Using PSCP command for copying files and directories
  15. Configuring SFTP/SSH access for LXC Containers
  16. Debugging programs on Linux using strace
  17. Generate Certificate Signing Request (CSR) for ssl certificates
  18. Split large files using split command in Linux
  19. Monitoring user activity with acct package
  20. Error in pushing changes to remote git repository
  21. Permanently authenticating with remote git repositories
  22. Passing command line arguments to Python script
  23. List users currently logged in
  24. Using Redir command for redirecting ports
  25. Importing Ldap configuration from file gives, "Wrong attributetype" error
  26. How To Change Account Passwords on an OpenLDAP Server
  27. Sending email through Gmail server using mailx command
  28. Fetching website resource over https using wget
  29. Delete downloaded file using Wget
  30. Using Oauth2l
  31. How to Backup and Restore LXC containers
  32. Fix ntfs disk is corrupt error
  33. Recover deleted files on ext3/ext4 file system using Photorec
  34. Convert pdf files to text files
  35. Viewing number of files in directory
  36. Using Rsync to copy all files recursively into one folder
  37. Using SED tool for replacing text in files
  38. Automate scp command using sshpass