Hi all,
I'm a linux novice and would like some help creating a bash script that I can setup on a cron. The purpose of the script is to write the size of each user's home directory to a csv file every night. I have it working great right now, but would like to add a third column that contains the timestamp (TimeStampFunc) of when the du finished for that folder. It seems the printf command cannot see or call TimeStampFunc possibly due to scope? Anyone know how I can add in a timestamp to every line of the csv that shows when that "du" was calculated?
I'm a linux novice and would like some help creating a bash script that I can setup on a cron. The purpose of the script is to write the size of each user's home directory to a csv file every night. I have it working great right now, but would like to add a third column that contains the timestamp (TimeStampFunc) of when the du finished for that folder. It seems the printf command cannot see or call TimeStampFunc possibly due to scope? Anyone know how I can add in a timestamp to every line of the csv that shows when that "du" was calculated?
Code:
#Clean up the previous night's run
rm /mnt/DATA/tech/scripts/NASReport.csv
rm /mnt/DATA/tech/scripts/NASReport.log
#TimeStamp Function
TimeStampFunc() {
date +"%F %T"
}
#Student Drive - THIS DOES NOT WORK WITH THE TIMESTAMPFUNC
for d in /mnt/DATA/student/drive/*; do
du -sm "$d"/* | awk {'printf ("%s,%s,%s\n", $2, $1, $(TimeStampFunc))'} >> /mnt/DATA/tech/scripts/NASReport.csv
echo "$(TimeStampFunc) Finished $d" >> /mnt/DATA/tech/scripts/NASReport.log
done
#Employee Drive - THIS WORKS WITHOUT THE TIMESTAMPFUNC
for d in /mnt/DATA/employee/drive/*; do
du -sm "$d"/* | awk {'printf ("%s,%s\n", $2, $1)'} >> /mnt/DATA/tech/scripts/NASReport.csv
echo "$(TimeStampFunc) Finished $d" >> /mnt/DATA/tech/scripts/NASReport.log
done