Cron Script to run every 5 minutes

27,840

Solution 1

  • crontab -e
  • add at the end */5 * * * 1-4 /path/to/script &
  • save and exit
  • the script is

    #!/bin/bash
    echo "$(date)" >> /tmp/memory.usage
    echo "$(free)" >> /tmp/memory.usage
    echo ""
    

see man 5 crontab for details. Or, an all-in-one cron line:

*/5 * * * 1-4 (echo $(date) && echo $(free) && echo "") >> /tmp/memory.usage

Solution 2

*/5 * * * * /path/to/script

Make the script executable before that. And make it accessible only for root if the script need elevated privileges.

You can follow the link for more examples Here

Share:
27,840
ars646
Author by

ars646

Updated on September 18, 2022

Comments

  • ars646
    ars646 over 1 year

    How would you use a cron deamon to execute a scheduled command such as gathering memory usage and adding that information to a file called /tmp/memory.usage, but only runs on Monday through Thursday every five minutes? I need to show the date and time before each new entry within the file. Please assist. Thank you in advance for any suggestions and help!

  • Paul
    Paul over 2 years
    This answer runs the job every day of the week and OP asked for Monday through Thursday.