Skip to content

Instantly share code, notes, and snippets.

@mitio
Created August 14, 2012 10:44
Show Gist options
  • Save mitio/3348120 to your computer and use it in GitHub Desktop.
Save mitio/3348120 to your computer and use it in GitHub Desktop.
Quick sync tool to be run in "Set UID" mode for a specific purpose
#include <stdio.h>
int main()
{
setuid(0);
printf("Starting...\n");
// Create directories
system("find /wow/deian/BFF -type d | sed -e 's/\\/deian//' | while read folder; do echo Creating folder $folder; mkdir -p $folder; done");
// Move files
system("find /wow/deian/BFF -type f | sed -e 's/\\/wow\\/deian\\///' | while read file; do echo Moving file $file; mv -f /wow/deian/$file /wow/$file; done");
// Remove empty source directories
system("find /wow/deian/BFF/*/* -type d 2>/dev/null | sort -r | while read folder; do echo Removing empty folder $folder; rmdir $folder; done");
// Set ownership of target files
system("chown -R nobody:nogroup /wow/BFF");
printf("Done.\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment