Task: need to tar yesteday logs in one file and gzip it.
Little bash code, just to save my time in future.
#!/bin/bash
src='/var/spool/etl/archive'
dt=`date --date="1 day ago" +"%Y-%m-%d"`
#create empty tar archive
tar cvf $src/$dt.tar --files-from /dev/null
for i in `ls -1 $src/*$dt* | grep -v gz | grep -v tar`; do
tar -rf $src/$dt.tar $i
rm -f $i
done
gzip $src/$dt.tar
src='/var/spool/etl/archive'
dt=`date --date="1 day ago" +"%Y-%m-%d"`
#create empty tar archive
tar cvf $src/$dt.tar --files-from /dev/null
for i in `ls -1 $src/*$dt* | grep -v gz | grep -v tar`; do
tar -rf $src/$dt.tar $i
rm -f $i
done
gzip $src/$dt.tar
0 Comments.