π§ Shell Scripting Interview Questions and Answers
1. β
Check if file exists in a path and is writable
FILE=”/path/to/file”
if [ -f “$FILE” ] && [ -w “$FILE” ]; then
echo “File exists and is writable.”
else
echo “File does not exist or is not writable.”
fi
2. β
Print list of names from a file
!/bin/bash
while read -r name; do
echo “$name”
done < names.txt
3. β
Create a file with name as date (yyy-MM-dd)
!/bin/bash
filename=$(date +%Y-%m-%d).txt
touch “$filename”
4. β
Mount a disk on a given filesystem
sudo mount /dev/sdb1 /mnt/data
5. β
Word count, grep specific word, get first/last 10 lines
Word count
wc -w filename.txt
Grep specific word
grep “word” filename.txt
First 10 lines
head -n 10 filename.txt
Last 10 lines
tail -n 10 filename.txt
π οΈ Jenkins Interview Questions
β
Write a basic Jenkins pipeline script
pipeline {
agent any
stages {
stage(‘Build’) {
steps {
echo ‘Buildingβ¦’
}
}
stage(‘Test’) {
steps {
echo ‘Running Testsβ¦’
}
}
stage(‘Deploy’) {
steps {
echo ‘Deployingβ¦’
}
}
}
}
π³ Docker Interview Questions
β
Write a Dockerfile to create a Python app image
Use official Python image
FROM python:3.9
Set working directory
WORKDIR /app
Copy app files
COPY . /app
Install dependencies
RUN pip install -r requirements.txt
Run app
CMD [“python”, “app.py”]
βΈοΈ Kubernetes Interview Questions
apiVersion: v1
kind: PersistentVolume
metadata:
name: my-pv
spec:
capacity:
storage: 1Gi
accessModes:
– ReadWriteOnce
hostPath:
path: “/mnt/data”
β
Write manifest template for Pod or Deployment
apiVersion: v1
kind: Pod
metadata:
name: my-pod
spec:
containers:
– name: my-container
image: nginx
π Deployment Template:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
spec:
replicas: 2
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
– name: my-container
image: nginx