diff --git a/main.rb b/main.rb index 07d9580..ff4d13e 100644 --- a/main.rb +++ b/main.rb @@ -8,10 +8,24 @@ args = ARGV if args[0] == '--parse' || args[0] == '-p' puts("[!] Opening log file at #{args[1]}") - logfile = File.open(args[1]) + + begin + logfile = File.open(args[1]) + rescue Errno::ENOENT + warn "[x] The file #{args[1]} was not found." + exit 1 + end + else puts('[!] Log file path not provided, assuming default access.log') - logfile = File.open('access.log', 'a') + + begin + logfile = File.open('access.log') + rescue Errno::ENOENT + warn '[x] Default file access.log not found. Specify an alternative log file to parse with -p or --parse.' + exit 1 + end + end data = logfile.read