Skip to content

Instantly share code, notes, and snippets.

@gustavonovaes
Last active December 7, 2017 12:53
Show Gist options
  • Save gustavonovaes/89b6371a3ec51a31f3fb4b36197aac80 to your computer and use it in GitHub Desktop.
Save gustavonovaes/89b6371a3ec51a31f3fb4b36197aac80 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# cron script to otimize space on file sharing server
#
# Written by Gustavo Novaes <[email protected]> for Mercantil Real
search_path=/mnt/samba
find $search_path -iname '*.csv' -or -iname '*.txt' -or -iname '*.mfd' | while IFS= read -r f; do
size=$(stat -c%s "$f")
size=`echo "$size / 1024 / 1024" | bc`
if [ "$size" -gt "2" ] && [ ! -f "${f%.*}.zip" ]; then
zip "${f%.*}.zip" "$f"
rm -f $f
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment