Skip to content

Instantly share code, notes, and snippets.

@astatham
Created May 11, 2011 09:12
Show Gist options
  • Save astatham/966154 to your computer and use it in GitHub Desktop.
Save astatham/966154 to your computer and use it in GitHub Desktop.
Hacked together script to find all my .R files, and git the changes (to be run daily as a cron job)
#!/bin/bash
#Important notes
#if backupdir is under homedir then backupdir must be included in the "$backupdir"/exclude file otherwise it will recurse
#also "$backupdir"/exclude file must not contain blank lines (match everything therefore backup nothing)
homedir="/home/aarsta"
backupdir="/home/aarsta/R_Backup"
find "$homedir" -name "*.R" | grep -v -f "$backupdir"/exclude | grep -o \\/.*\\/ | sort | uniq | sed -e "s%"$homedir"/%"$backupdir"/%" -e 's% %_%g'| xargs mkdir -p
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for file in `find "$homedir" -name "*.R" | grep -v -f "$backupdir"/exclude`;
do
file2=`echo $file | sed -e "s%"$homedir"/%"$backupdir"/%" -e 's% %_%g'`
cp -up $file $file2;
done
IFS=$SAVEIFS
git add -A
msg=`date`
msg=`echo $msg | sed 's% %_%g'`
git commit -am $msg
/home/aarsta/analysis-utils
/home/aarsta/tmp
/home/aarsta/junk
/home/aarsta/R
/home/aarsta/.mozilla
/home/aarsta/R_Backup
/home/aarsta/.git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment