Orion09

countraiddrives

Mar 18th, 2025 (edited)
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. local fs = require("filesystem")
  2.  
  3. -- Function to capture command output
  4. local function capture(cmd)
  5. local f = io.popen(cmd, "r")
  6. local output = f:read("*a")
  7. f:close()
  8. return output
  9. end
  10.  
  11. -- Get the mount command output
  12. local mountOutput = capture("mount")
  13.  
  14. -- Ensure the combined directory exists
  15. local combinedDir = "/mnt/combined"
  16. if not fs.exists(combinedDir) then
  17. fs.makeDirectory(combinedDir)
  18. end
  19.  
  20. local count = 0
  21.  
  22. -- Print the full mount output for inspection
  23. print("Full mount command output:")
  24. print(mountOutput)
  25.  
  26. -- Parse and debug mount points
  27. print("\nDetected mount points:")
  28. for line in mountOutput:gmatch("[^\r\n]+") do
  29. -- Adjusted pattern to capture any mount point, accounting for whitespace
  30. local mountpoint = string.match(line, " on%s+(%S+)%s+type ")
  31. if mountpoint then
  32. print("Found: " .. mountpoint)
  33. -- Check if it matches the expected RAID drive pattern
  34. if mountpoint:match("^/mnt/f") then
  35. count = count + 1
  36. -- Link files to the combined directory
  37. for filename in fs.list(mountpoint) do
  38. local fullpath = mountpoint .. "/" .. filename
  39. local linkpath = combinedDir .. "/" .. filename
  40. if not fs.exists(linkpath) then
  41. fs.link(fullpath, linkpath)
  42. end
  43. end
  44. end
  45. end
  46. end
  47.  
  48. print("\nNumber of RAID drives processed: " .. count)
Advertisement
Add Comment
Please, Sign In to add comment