First I have a file derived from the last command in Linux. But I have hard time to figure out how to extract and sort every IP address and last command for each user. This actually how the file looks like:
frank pts/5 192.220.128.18 Thu Dec 13 21:47 still logged in
enha pts/3 17.0.0.206 Thu Dec 12 21:09 still logged in
skr pts/1 184.31.240.205 Thu Dec 19 18:57 - 21:18 (02:20)
skr pts/6 182.31.40.205 Thu Oct 24 16:42 - 16:53 (00:10)
skr pts/7 182.31.40.205 Thu Oct 24 15:35 - 15:42 (00:06)
frank pts/6 177.31.20.205 Thu Avr 24 15:33 - 15:42 (00:08)
sama pts/5 190.150.128.25 Thu Avr 25 15:03 - 17:03 (02:00)
ccorn pts/3 100.10.128.27 Thu Sep 24 14:17 - 14:26 (00:08)
And this is the output I'm looking for:
UserName,Last Login,Total Logins,IP Address List
frank,Nov 13 21:47,2,192.220.128.18;177.31.20.205
skr,Dec 19 18:57,3,182.31.40.205;188.31.40.205
sama,Avr 25 15:03,1,190.150.128.2
i was able to count for example how may each user login but i could not figure the rest and sort them as expect to be this is what I done so far
frequencies = Hash.new(0)
login = []
lines =File.readlines("file.txt")
lines.each do |line|
login << line.split[0]
end
#p login
login.each do |user|
frequencies[user] += 1
end
p frequencies
and thanks in advance
Aucun commentaire:
Enregistrer un commentaire