Last active
June 22, 2016 16:45
-
-
Save ziadoz/191253862e7e68891f8b to your computer and use it in GitHub Desktop.
Plesk Log File Cleanup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
# Cleanup Plesk 10.3 Log Files | |
# A handy little script to truncate Plesk log files. | |
# Useful for when you change the subscription log rotation settings. | |
# Make sure you backup your log files beforehand. | |
# | |
# Usage: | |
# ruby cleanup-plesk-logs.rb /var/www/vhosts | |
# ruby cleanup-plesk-logs.rb /var/www/vhosts -f | |
site_dir, execute = ARGV | |
site_dir = File.expand_path(site_dir.to_s) | |
execute = (execute == '-f') | |
abort "Please specify the website path." if site_dir.nil? | |
sites = Dir.glob(File.join(site_dir, '*')) | |
log_dir = 'statistics/logs' | |
logs = ['access_log', 'error_log', 'access_log.process', 'error_log.process', 'access_log.processed', 'error_log.processed'] | |
sites.each do |site| | |
next unless Dir.exists?(site) | |
puts File.basename(site) + ': ' | |
logs.each do |log| | |
log = File.join(site, log_dir, log) | |
next unless File.exists?(log) | |
cmd = 'sudo cp /dev/null ' + log | |
result = true | |
result = system(cmd) if execute | |
puts cmd + ' -> ' + (result ? 'true' : 'false') | |
end | |
puts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This looks like the solution for me, how I'd use this file please? I'm used to php development, I don't recognise a .rb file.
Thank you.