Skip to content

Instantly share code, notes, and snippets.

@mplscorwin
Created January 15, 2014 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mplscorwin/8445328 to your computer and use it in GitHub Desktop.
Save mplscorwin/8445328 to your computer and use it in GitHub Desktop.
fix ownership of cassandra's files when someone goes and runs it other than from "service start cassandra" (CentOS 6)
#!/bin/bash
################################################################################
#
# shell script to fix ownership of all files under each entry in SEARCH_PATH
#
# Change SEARCH_PATH as needed.
# NOTE: script has no output if it does no work.
#
################################################################################
# space seperated list of paths
SEARCH_PATHS='/home/cassandra/data /clogs/processlog /clogs/commitlog'
# incorrect user for which we are searching
SEARCH_USER=root
# correct user/group
CHOWN_ARGS=cassandra.cassandra
### work happens here
CHANGE_COUNT=0
for DIR in $SEARCH_PATHS; do
CHANGE_COUNT=$(( $CHANGE_COUNT + `find $DIR -user $SEARCH_USER -exec chown $CHOWN_ARGS {} \; -print | wc -l`))
done
if [[ $CHANGE_COUNT -gt 0 ]]; then
echo [WARNING] ownership of $CHANGE_COUNT files changed from root.\? to $CHOWN_ARGS
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment