Linux uses the Cron+at implementation to randomly execute commands within a certain time period _linux

Source: Internet
Author: User
Tags sleep

Write a script to sign in, but do not want to always in the time to check in the database, otherwise the record in the data base is too fake, so you need to determine the time period, randomly selected time to execute, finally thought of using CRON+AT implementation

The simple idea is that Cron sets a starting time, like 6 a day in the morning, and a random 2-350 minutes later to sign in.

So as long as this

0 6 * * * echo ' sleep ' $ (shuf-i 1-60-n 1) ';d ate >>/tmp/xxxx.txt ' |at now + $ (shuf-i 2-350-n 1) min

The reason why we have a random 1-60 second sleep is because at is the whole point of execution, do not want to have the database only the entire minutes of the check-in record.

This saves a lot of resources than the way to sleep directly in cron, and the maximum dwell time is no more than 60 seconds.

To keep the simplicity in cron, you can then wrap a script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.