Skip to content

Instantly share code, notes, and snippets.

@murphybytes
Created January 15, 2025 21:22
Show Gist options
  • Save murphybytes/7c0fafde51c9e95b4cc6b18174031f13 to your computer and use it in GitHub Desktop.
Save murphybytes/7c0fafde51c9e95b4cc6b18174031f13 to your computer and use it in GitHub Desktop.
Suspend all cronjobs in namespace
#!/bin/bash
#########################################################################
# Usage: suspend-cronjobs.sh <namespace>
# Suspends cronjobs in a namespace
#########################################################################
if ! command -v kubectl &> /dev/null
then
echo "kubectl must be present in order to run this script"
exit 1
fi
for job in $(kubectl get cj -n "$1" | tail -n +2 | cut -d " " -f 1)
do
kubectl patch cronjobs "$job" -n "$1" -p '{"spec" : {"suspend" : true }}'
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment