Skip to content

Instantly share code, notes, and snippets.

@Dineshs91
Last active August 18, 2017 19:24
Show Gist options
  • Save Dineshs91/2d34c58da8e88671edc41d138bfa8474 to your computer and use it in GitHub Desktop.
Save Dineshs91/2d34c58da8e88671edc41d138bfa8474 to your computer and use it in GitHub Desktop.
Add cron job to the provided machines
#! /bin/bash
# Usage:
# sh add_cron.sh [key_file] [user] ip
key_file=$1
username=$2
ip=$3
if [ $# -le 2 ]; then
echo "Usage: sh add_cron.sh [key_file] [user] ip"
exit 1;
fi
ssh -i "$key_file" "$username"@"$ip" "(crontab -l 2>/dev/null; echo '00 00 * * * docker container prune -f && docker image prune -f &> /var/log/cleanup.log') | crontab -"
@Dineshs91
Copy link
Author

Add a cron job to remove docker unused images and containers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment