daily pastebin goal
35%
SHARE
TWEET

Untitled

a guest Dec 16th, 2015 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. INIZIO SCRIPT
  2.  
  3. #!/usr/bin/env python3
  4.  
  5. import subprocess
  6. import time
  7. import shutil
  8.  
  9. #--
  10. target_folder = "/path/to/target_folder"
  11. excluded = ["media_extern"]
  12. #--
  13.  
  14. def get_mountedlist():
  15.     return [(item.split()[0].replace("├─", "").replace("└─", ""),
  16.              item[item.find("/"):]) for item in subprocess.check_output(
  17.             ["/bin/bash", "-c", "lsblk"]).decode("utf-8").split("\n") if "/" in item]
  18.  
  19. def identify(disk):
  20.     command = "find /dev/disk -ls | grep /"+disk
  21.     output = subprocess.check_output(["/bin/bash", "-c", command]).decode("utf-8")
  22.     if "usb" in output:
  23.         return True
  24.     else:
  25.         return False
  26.  
  27. done = []
  28. while True:
  29.     mounted = get_mountedlist()
  30.     new_paths = [dev for dev in get_mountedlist() if not dev in done and not dev[1] == "/"]
  31.     valid = [dev for dev in new_paths if (identify(dev[0]), dev[1].split("/")[-1]  in excluded) == (True, False)]
  32.     for item in valid:
  33.         target = target_folder+"/"+item[1].split("/")[-1]
  34.         try:
  35.             shutil.rmtree(target)
  36.         except FileNotFoundError:
  37.             pass
  38.         shutil.copytree(item[1], target)
  39.     done = mounted
  40.     time.sleep(4)
  41.  
  42. FINE SCRIPT
  43.  
  44. Risposta al comando "lsblk":
  45.  
  46. NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
  47. sda      8:0    0 232.9G  0 disk
  48. ├─sda1   8:1    0   100M  0 part
  49. ├─sda2   8:2    0 232.4G  0 part
  50. └─sda3   8:3    0   449M  0 part
  51. sdb      8:16   1  29.8G  0 disk
  52. └─sdb1   8:17   1  29.8G  0 part /cdrom
  53. sdc      8:32   1   7.5G  0 disk
  54. └─sdc1   8:33   1   7.5G  0 part /media/ubuntu/4C9B-DB6A
  55. sr0     11:0    1  1024M  0 rom  
  56. loop0    7:0    0   1.1G  1 loop /rofs
  57.  
  58.  
  59.  
  60. Risposta al comando "uname -a":
  61.  
  62. Linux ubuntu 4.2.0-16-generic #19-Ubuntu SMP Thu Oct 8 15:35:06 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top