Skip to content

Instantly share code, notes, and snippets.

@balkian
Created December 17, 2012 21:07
Show Gist options
  • Save balkian/4322258 to your computer and use it in GitHub Desktop.
Save balkian/4322258 to your computer and use it in GitHub Desktop.
Script to copy all the logs with a certain filename (YYY-MM-DD_<name>.log) to a folder for the day, tar.gz the folder and send it to a remote host.
#!/bin/bash
tosend=""
for i in *.log; do
dir=$(echo $i | awk '{split($1,a,"_"); print a[1]}');
if [ ! -d $dir ]; then
mkdir $dir;
fi;
mv $i $dir;
tosend="$tosend\n$dir"
done
for i in $(echo -e $tosend | uniq);do
echo Compressing $i
tar -zcvf $i.tar.gz $i
scp $i.tar.gz user@server
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment