Skip to content

Instantly share code, notes, and snippets.

@geoffgarside
Created September 13, 2014 10:15
Show Gist options
  • Save geoffgarside/ad6225af344c673457d1 to your computer and use it in GitHub Desktop.
Save geoffgarside/ad6225af344c673457d1 to your computer and use it in GitHub Desktop.
Ruby script to return Exim Queue IDs of messages with a given SMTP Auth value
#!/usr/bin/env ruby
INPUT_DIR = '/var/spool/exim/input/'
AUTH_ID = '-auth_id '
auth_id = ARGV[0]
if auth_id.nil? || auth_id == ""
puts "Usage: #{$0} auth_id"
exit
end
needle = "#{AUTH_ID}#{auth_id}"
length = AUTH_ID.length
Dir.foreach(INPUT_DIR) do |file|
next if file == '.' || file == '..'
next unless file =~ /\-H$/
path = File.join(INPUT_DIR, file)
data = File.read(path)
data.lines.each do |line|
if AUTH_ID == line[0,length] # Find -auth_id line
if needle == line.strip # Compare with needle
puts file[0..-3] # Emit message ID
end
break # Leave loop whether we've found needle or not
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment