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!
- 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 ""
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