Tuesday, 7 November 2017

Script for gzip / delete Access and Error logs / moving old files to new directory based on date

1. EXECUTE COMMAND

#!/bin/bash
# changing ownership of order xml files
find /order/OrderXML/*.xml -mmin -60 -exec chmod 664 {} \;

2. GZIP LOGS AND DELETING LOGS

# gzip access log older than 2 day
find /HTTPServer/logs -mmin +1440 -type f -iname "access*" ! -iname "access*.gz" -exec gzip {} \;
# Deleting access logs older than 20 days
find /HTTPServer/logs -mtime +20 -type f -iname "access*" -delete
find /HTTPServer/logs -mmin +1440 -type f -iname "error*" ! -iname "error*.gz" -exec gzip {} \;
find /HTTPServer/logs -mtime +20 -type f -iname "error*" -delete

3. MOVING FILES BASED ON DATE

find /sourcedirectory -mtime +365 -type f -exec mv "{}" /destination/directory/ \;
find /sourcedirectory -mtime +365 -type f -exec ls -l "{}" /destination/directory/ \;
find /OrderXML/ -mtime +600 -type f -exec ls -l "{}" /OrderXML/OrderXmlBackup/ \;
find /sourcedirectory -maxdepth 1 -mtime +365 -exec mv "{}" /destination/directory/ \;
find /sourcedirectory -type f -mtime +365 -exec mv "{}" /destination/directory/ \;

find . -newer 2000002017_13.15.00.xml  -type f -exec ls -l "{}" \;
find /OrderXML/2015/ -newer 2000002017_13.15.00.xml  -type f -exec ls -l "{}" \;

find /OrderXML/2015/ -newer 2000004004_14.10.01.xml  -type f -exec mv "{}" /OrderXML/2015/Dec-15 \;

No comments:

Post a Comment