Skip to content

Instantly share code, notes, and snippets.

@Dineshs91
Last active August 18, 2017 19:24
Show Gist options
  • Select an option

  • Save Dineshs91/2d34c58da8e88671edc41d138bfa8474 to your computer and use it in GitHub Desktop.

Select an option

Save Dineshs91/2d34c58da8e88671edc41d138bfa8474 to your computer and use it in GitHub Desktop.

Revisions

  1. Dineshs91 revised this gist Aug 18, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion add_cron.sh
    Original file line number Diff line number Diff line change
    @@ -3,8 +3,8 @@
    # Usage:
    # sh add_cron.sh [key_file] [user] ip

    username=$2
    key_file=$1
    username=$2
    ip=$3

    if [ $# -le 2 ]; then
  2. Dineshs91 revised this gist Aug 18, 2017. 1 changed file with 7 additions and 13 deletions.
    20 changes: 7 additions & 13 deletions add_cron.sh
    Original file line number Diff line number Diff line change
    @@ -1,21 +1,15 @@
    #! /bin/bash

    # Usage:
    # sh add_cron.sh [key_file] [user] [ip1, ip2, ...]
    # sh add_cron.sh [key_file] [user] ip

    username=$1
    key_file=$2
    username=$2
    key_file=$1
    ip=$3

    if [ $# -le 4 ]; then
    echo "Usage: sh add_cron.sh [key_file] [user] [ip1, ip2, ...]"
    if [ $# -le 2 ]; then
    echo "Usage: sh add_cron.sh [key_file] [user] ip"
    exit 1;
    fi

    total_ips=$#

    for ip in `seq 3..$total_ips`
    do
    echo 'ssh -i "${key_file}" "${username}"@"${ip}"'
    done

    ssh -i key_file username@ip
    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 -"
  3. Dineshs91 created this gist Aug 18, 2017.
    21 changes: 21 additions & 0 deletions add_cron.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    #! /bin/bash

    # Usage:
    # sh add_cron.sh [key_file] [user] [ip1, ip2, ...]

    username=$1
    key_file=$2

    if [ $# -le 4 ]; then
    echo "Usage: sh add_cron.sh [key_file] [user] [ip1, ip2, ...]"
    exit 1;
    fi

    total_ips=$#

    for ip in `seq 3..$total_ips`
    do
    echo 'ssh -i "${key_file}" "${username}"@"${ip}"'
    done

    ssh -i key_file username@ip