Why cron job fails to redirect top command output, to a file, using a shell script?
Issue
-
A
cron jobfails to redirecttopcommand output, to a file, using ashell script.# cat /scripts/cpu-usage.sh !/bin/bash date >> /tmp/stats/cpu_stats top |head -n 3 |tail -n 1 >> /tmp/stats/cpu_stats # grep cpu /etc/crontab */5 * * * * root /scripts/cpu-usage.sh # tail -f /tmp/stats/cpu_stats Mon Jul 17 21:05:01 IST 2023 Mon Jul 17 21:10:01 IST 2023 Mon Jul 17 21:15:01 IST 2023
Environment
- Red Hat Enterprise Linux 6
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.