I would like to have a script that will count the number of files at the top of the hour of soome directories and mail the results to me.
I was thinking on :
Instead of a while, can you use cron? It is usually more efficient than having a resident process sleeping.
#!/bin/ksh
# usage.shl
for dir in /directory1/subdir directory2/subdir
do
echo "$dir $( du $dir |wc -l)"
done > ./message
mailx -s 'dir usage' me@mycompany.com < ./message
Using crontab
# five minutes after every hour
5 * * * * * /path/to/usage.shl 2 > /path/to/usage.log
no crontab
#!/bin/ksh
# usage.shl
while :
do
for dir in /directory1/subdir directory2/subdir
do
echo "$dir $( du $dir |wc -l)"
done > ./message
mailx -s 'dir usage' me@mycompany.com < ./message
sleep 3600
done
This execution time will drift over time because sleep is not guranteed to "wake up" precisely because of system load.
You can use bash. But those errors are caused by the shell being /bin/sh - a Bourne shell
When crond runs a job in Solaris, by default, it starts the job with /bin/sh. If you do not change that behavior you have to code in Bourne shell. Since you got that error you cannot have copied the original code with the shebang I gave you. The original invoked ksh. use