Automation & Scripting Flashcards
7 cards from real POC practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 Automation & Scripting flashcards as text
In Python automation, what does `shutil.copy2(src, dst)` do differently from `shutil.copy(src, dst)`?
Answer: It also preserves the source file's metadata (timestamps, permissions)
`shutil.copy2()` calls `shutil.copy()` plus `shutil.copystat()`, preserving timestamps and permission bits on the destination.
Which pattern correctly uses Python's `logging` module to write WARNING-level messages to a file?
Answer: logging.basicConfig(filename='app.log', level=logging.WARNING)
`logging.basicConfig(filename=..., level=logging.WARNING)` configures the root logger to write WARNING and above to the specified file.
What does the `Fabric` library primarily automate in Python scripts?
Answer: SSH remote command execution and file transfer
Fabric wraps Paramiko to provide a high-level API for running shell commands on remote servers over SSH and transferring files with `put`/`get`.
In a Python cron-like scheduler, which expression using the `schedule` library runs a job every Monday at 9 AM?
Answer: schedule.every().monday.at('09:00').do(job)
The `schedule` library uses a fluent API: `.every().monday.at('09:00').do(job)` registers a weekly job on Monday at the specified time.
What exception should you catch when a `subprocess.run()` call exceeds its `timeout` parameter?
Answer: subprocess.TimeoutExpired
`subprocess.TimeoutExpired` is raised when the child process doesn't complete within the specified `timeout` seconds.
Which `re` module function returns all non-overlapping matches of a pattern in a string as a list?
Answer: re.findall()
`re.findall()` scans the string and returns a list of all matches; if groups are present, it returns a list of groups instead.
When writing a Python script that must be idempotent, what technique prevents a file-creation step from failing on re-runs?
Answer: Check `if not os.path.exists(path)` before creating, or use `exist_ok=True` where available
Guarding with an existence check or `exist_ok=True` (for directories) ensures the script succeeds on repeated runs without side effects.