Skip to content

Instantly share code, notes, and snippets.

@timoteoramos
Created December 29, 2019 19:50
Show Gist options
  • Save timoteoramos/cdcc6fe8bbf58f256df18b0fb1b2ff4e to your computer and use it in GitHub Desktop.
Save timoteoramos/cdcc6fe8bbf58f256df18b0fb1b2ff4e to your computer and use it in GitHub Desktop.

Manual Rotate Script

It's a simple file or directory rotation script. Just set up the 2 variables (OBJECT and ROTATE) and run the script.

Example Usage

OBJECT="backup.tar.bz2" ROTATE=7 bash manualrotate.sh

#!/bin/bash
if [ -e $OBJECT ]
then
mv $OBJECT $OBJECT.0
if [ -e $OBJECT.$ROTATE ]; then rm $OBJECT.$ROTATE; fi
for (( i = $ROTATE; i > 1; i-- ))
do
if [ -e $OBJECT.$((i-1)) ] && [ ! -e $OBJECT.$((i)) ] && [ -e $OBJECT.$((i-2)) ]; then mv $OBJECT.$((i-1)) $OBJECT.$i; fi
done
mv $OBJECT.0 $OBJECT.1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment