<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"><channel><title>LINICKX.com</title><link>https://www.linickx.com/</link><description></description><lastBuildDate>Thu, 26 Jun 2008 19:00:00 +0100</lastBuildDate><item><title>Bash script to fix file permissions recursively</title><link>https://www.linickx.com/bash-script-to-fix-file-permissions-recursively</link><description>&lt;p&gt;I love the redhat implementation of cron, simply drop a shell script
into &lt;code&gt;/etc/cron.daily/&lt;/code&gt; and your script will be executed every day (&lt;em&gt;by
default at 4am&lt;/em&gt;).&lt;/p&gt;
&lt;p&gt;Recently I've been having a small
&lt;a href="https://sourceforge.net/forum/forum.php?thread_id=1961180&amp;amp;forum_id=440751"&gt;problem&lt;/a&gt;
with &lt;a href="http://mediatomb.cc/"&gt;mediatomb&lt;/a&gt;, further investigation lead me to
&lt;a href="https://sourceforge.net/forum/message.php?msg_id=4828164"&gt;a "Inotify thread caught exception"
error&lt;/a&gt; which
can be fixed by recursively resetting your file permissions.&lt;/p&gt;
&lt;p&gt;What I have done to fix the issue is save the following code as
&lt;code&gt;/etc/cron.daily/fix_mt.sh&lt;/code&gt; and 'jobs a gooden' :cool:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;#!/bin/bash
# Load up your mediatomb directories...
MediaTombDirectories[0]="/home/me/Videos"
MediaTombDirectories[1]="/home/me/Music"
# add more if needbe
# MediaTombDirectories[2]="/home/me/files"

# Setup find correctly.
export IFS=$'\n'

# Loop through our array.
for x in ${MediaTombDirectories[@]}
    do 
        # Find all directories &amp;amp; subdirectories
        for i in $(find $x -type d) 
            do 
                # Fix Permissions
                chmod -c 775 $i
                chown -c me:user $i
            done

        # Find all Files
        for i in $(find $x -type f) 
            do 
                # Fix Permissions
                chmod -c 664 $i
                chown -c me:user $i
            done
    done
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;&lt;br /&gt;
Quick tip:&lt;/strong&gt; You (&lt;em&gt;or root&lt;/em&gt;) will get e-mailed every time this
executes, you can make the script more verbos by changing all "&lt;code&gt;-c&lt;/code&gt;" to
"&lt;code&gt;-v&lt;/code&gt;", or make it silent by removing the "&lt;code&gt;-c&lt;/code&gt;" altogether.&lt;/p&gt;
&lt;p&gt;Enjoy!&lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">nick</dc:creator><pubDate>Thu, 26 Jun 2008 19:00:00 +0100</pubDate><guid isPermaLink="false">tag:www.linickx.com,2008-06-26:bash-script-to-fix-file-permissions-recursively</guid><category>bash</category><category>cron</category><category>Linux</category><category>mediatomb</category></item></channel></rss>