Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. # Obtain a list of files in /usr/bin with the corresponding package they belong to:
  2. packfiles = (`dpkg -S /usr/bin/* 2>/dev/null`).split("n") # errors written to /dev/null
  3.  
  4. # For each executable in a package, get the last accessed time and save the latest time per package
  5. packagetimes = packfiles.reduce({}) {|packages, pf|
  6. package, file = pf.split(' ') # Split line into package name and file path
  7. package.chomp!(':') # Remove last colon after package name
  8. packages[package]
  9. lat = open(file).atime # Get the last accessed time of the file
  10. #Take greater of package last change time or time for file for package:
  11. packages[package] = (packages[package] && packages[package] > lat ? packages[package] : lat)
  12. packages #for next reduce iteration
  13. }.
  14. # Produce a sorted list of packages and times
  15. reduce([]) {|arr, entry| arr << [entry[0],entry[1]] }. # Create array with package, time
  16. sort_by {|line| line[1]} # Sort array by time
  17.  
  18. # Write out the list of packages and times
  19. open('./pusage.txt', 'w') {|out|
  20. packagetimes.each {|pt|
  21. out << "#{pt[0]}t#{pt[1]}n"
  22. }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement