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!


2 Answers 2

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

    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

*/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

  • This answer runs the job every day of the week and OP asked for Monday through Thursday.
    – Paul
    Jan 23, 2022 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.