Automation scripting

Advanced Level

Expert-level automation and scripting interview questions covering debugging, signal handling, remote execution, and advanced pipeline concepts.

Advanced Level

This section covers expert-level concepts in automation and scripting, including advanced debugging techniques, signal handling, remote execution, and complex pipeline configurations.

How do you debug a Bash script?

Use set -x for debugging:

#!/bin/bash
set -x
echo "Debugging mode enabled"

How do you trap signals in a Bash script?

trap "echo 'Script interrupted'; exit" SIGINT SIGTERM

Catches Ctrl+C (SIGINT) and terminates gracefully.

What is the difference between $(command) and backticks `command` in Bash?

Both execute commands, but $(command) is preferred as it's nestable.

How do you handle multiline commands in a Bash script?

Use \ for line continuation:

echo "This is a \
multiline command"

How do you use conditionals inside a YAML file?

With Jinja2 templating in Ansible:

tasks:
  - name: Install package
    yum:
      name: httpd
    when: ansible_os_family == "RedHat"

How do you encrypt secrets in YAML?

Use Ansible Vault:

ansible-vault encrypt secrets.yaml

How do you execute a Python script inside a Bash script?

python3 <<EOF
print("Hello from Python")
EOF

What is the difference between continue and break in Bash loops?

  • break exits the loop entirely.
  • continue skips the current iteration.

How do you parse a JSON file in Bash?

Use jq:

cat data.json | jq '.key'

How do you use arrays in Groovy?

def arr = ["a", "b", "c"]
println arr[0]

What is a Jenkins shared library in Groovy?

A reusable pipeline function stored in Git.

How do you set a timeout for a script in Bash?

timeout 10s ./script.sh

How do you execute a Bash function in a subshell?

(my_function)

Runs in a new shell, not affecting the parent script.

How do you use Python to send an HTTP request?

import requests
response = requests.get("https://example.com")
print(response.text)

How do you handle authentication in a Python script?

import requests
requests.get("https://example.com", auth=("user", "pass"))

How do you find and replace text in YAML files?

Use yq:

yq e '.name="NewValue"' -i config.yaml

How do you define a multi-stage Jenkins pipeline in Groovy?

pipeline {
    agent any
    stages {
        stage('Build') { steps { echo "Building..." } }
        stage('Test') { steps { echo "Testing..." } }
    }
}

What is an inline script in a CI/CD pipeline?

Running a script directly inside a pipeline (e.g., GitHub Actions, Jenkins).
Example in GitHub Actions:

jobs:
  build:
    steps:
      - run: echo "Inline script execution"

How do you execute a script remotely via SSH in Bash?

ssh user@server 'bash -s' < local_script.sh

How do you ensure idempotency in an Ansible playbook?

Ansible modules ensure idempotency by only making changes when needed.

On this page