Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Obtain a list of files in /usr/bin with the corresponding package they belong to:
- packfiles = (`dpkg -S /usr/bin/* 2>/dev/null`).split("n") # errors written to /dev/null
- # For each executable in a package, get the last accessed time and save the latest time per package
- packagetimes = packfiles.reduce({}) {|packages, pf|
- package, file = pf.split(' ') # Split line into package name and file path
- package.chomp!(':') # Remove last colon after package name
- packages[package]
- lat = open(file).atime # Get the last accessed time of the file
- #Take greater of package last change time or time for file for package:
- packages[package] = (packages[package] && packages[package] > lat ? packages[package] : lat)
- packages #for next reduce iteration
- }.
- # Produce a sorted list of packages and times
- reduce([]) {|arr, entry| arr << [entry[0],entry[1]] }. # Create array with package, time
- sort_by {|line| line[1]} # Sort array by time
- # Write out the list of packages and times
- open('./pusage.txt', 'w') {|out|
- packagetimes.each {|pt|
- out << "#{pt[0]}t#{pt[1]}n"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement