Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- INIZIO SCRIPT
- #!/usr/bin/env python3
- import subprocess
- import time
- import shutil
- #--
- target_folder = "/path/to/target_folder"
- excluded = ["media_extern"]
- #--
- def get_mountedlist():
- return [(item.split()[0].replace("├─", "").replace("└─", ""),
- item[item.find("/"):]) for item in subprocess.check_output(
- ["/bin/bash", "-c", "lsblk"]).decode("utf-8").split("\n") if "/" in item]
- def identify(disk):
- command = "find /dev/disk -ls | grep /"+disk
- output = subprocess.check_output(["/bin/bash", "-c", command]).decode("utf-8")
- if "usb" in output:
- return True
- else:
- return False
- done = []
- while True:
- mounted = get_mountedlist()
- new_paths = [dev for dev in get_mountedlist() if not dev in done and not dev[1] == "/"]
- valid = [dev for dev in new_paths if (identify(dev[0]), dev[1].split("/")[-1] in excluded) == (True, False)]
- for item in valid:
- target = target_folder+"/"+item[1].split("/")[-1]
- try:
- shutil.rmtree(target)
- except FileNotFoundError:
- pass
- shutil.copytree(item[1], target)
- done = mounted
- time.sleep(4)
- FINE SCRIPT
- Risposta al comando "lsblk":
- NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
- sda 8:0 0 232.9G 0 disk
- ├─sda1 8:1 0 100M 0 part
- ├─sda2 8:2 0 232.4G 0 part
- └─sda3 8:3 0 449M 0 part
- sdb 8:16 1 29.8G 0 disk
- └─sdb1 8:17 1 29.8G 0 part /cdrom
- sdc 8:32 1 7.5G 0 disk
- └─sdc1 8:33 1 7.5G 0 part /media/ubuntu/4C9B-DB6A
- sr0 11:0 1 1024M 0 rom
- loop0 7:0 0 1.1G 1 loop /rofs
- Risposta al comando "uname -a":
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement