Help with bash script

Status
Not open for further replies.

Hoof

Cadet
Joined
Dec 29, 2018
Messages
1
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?

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
 

millst

Contributor
Joined
Feb 2, 2015
Messages
141
The awk command isn't going to be aware of your function. How about just passing the date command directly?

-tm
 
Status
Not open for further replies.
Top