This section covers more advanced concepts in automation and scripting, including error handling, scheduling, and integration with various DevOps tools.
How do you pass arguments to a Bash script?
#!/bin/bashecho "Hello, $1!"
Run: ./script.sh DevOps → Output: Hello, DevOps!
How do you handle errors in Bash scripts?
Use set -e to stop execution on errors.
What is an Ansible playbook?
A YAML file that defines automation tasks for servers.
How do you handle exceptions in Python?
try: print(1 / 0)except ZeroDivisionError: print("Cannot divide by zero")
How do you schedule a script with Cron?
Edit crontab -e and add:
0 5 * * * /path/to/script.sh
Runs the script daily at 5 AM.
How do you execute a Groovy script in Jenkins?
Use script {} inside a Jenkins pipeline.
How do you create a list in Python?
mylist = [1, 2, 3]print(mylist[0])
What is sed in Bash?
Used for text replacement. Example:
sed -i 's/old/new/g' file.txt
How do you define a dictionary in Python?
mydict = {"name": "DevOps"}print(mydict["name"])
How do you validate a YAML file?
Use yamllint or kubectl apply -f --dry-run=client.