Skip to content

Instantly share code, notes, and snippets.

@rafaelbiriba
Last active March 7, 2024 03:19
Show Gist options
  • Star 33 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rafaelbiriba/0ee7ca2baec1ef80a878c825295f09e1 to your computer and use it in GitHub Desktop.
Save rafaelbiriba/0ee7ca2baec1ef80a878c825295f09e1 to your computer and use it in GitHub Desktop.
Generate tree report file on NAS and send it by email (optional)
#!/bin/bash
# Creates DISK0.tree, DISK1.tree, DISKx.tree inside each disk, with the output of tree command.
# After generating the report, it send via email using mail.
# To add more disks, just add DISK[x]=/full/path to the disk. Just make sure that the array index are sequencial.
# Why this?
# With the reports from tree, in case of disk failure, you will know which file got lost and you can recover them, downloading or via backups.
# GIST: https://gist.github.com/rafaelbiriba/0ee7ca2baec1ef80a878c825295f09e1
EMAIL_ADDRESS="" # EMAIL_ADDRESS="email@gmail.com" or leave it blank "" to disable email
DISKS[0]="/srv/dev-disk-by-id-ata-WDC_WD80EMAZ-00WJTA0_ABC123-part1"
DISKS[1]="/srv/dev-disk-by-id-ata-WDC_WD80EMAZ-00WJTA0_XYZ456-part1"
#DISKS[2]="/full/path/to/disk/mount"
### DON'T CHANGE BELOW ###
email_output_tmp=$(mktemp)
date=$(date +"%Y-%m-%d")
for i in ${!DISKS[@]}; do
cd ${DISKS[$i]}
echo "Disk tree report from $date" > "DISK$i.tree"
echo "DISK$i - ${DISKS[$i]}" >> "DISK$i.tree"
echo "=================================================================" >> "DISK$i.tree"
tree -h >> "DISK$i.tree"
cat "DISK$i.tree" >> $email_output_tmp
done
if [ "$EMAIL_ADDRESS" != "" ]; then
/usr/bin/mail -s "Disk tree report from $date" "$EMAIL_ADDRESS" < $email_output_tmp
rm $email_output_tmp
fi
@iamjoewoods
Copy link

Can this be used on Windows 10?

@rafaelbiriba
Copy link
Author

Can this be used on Windows 10?

Sorry, this is just for unix based systems :(

@chapmanjacobd
Copy link

for windows you can use SpaceSniffer and export a list of files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment