Blosxom Time Bug and Changing Lots of Permissions with a Shell Script
You may have noticed Glitchnyc.com was a blank slate for the past few hours.
The server went down, and since it's up for around a year at a time, I've never gotten around to worrying too much about what happens when the power drops and I have to worry about a reboot. I simply restart the mail server, apache and mysql, and everything is good.
The only catch was that this time, blosxom came back empty. I've seen this before, but as you may know if you know me personally, I have a memory like swiss cheese, so the fix had fallen right out of my head.
I looked at my file permissions, and my paths, and even blew open my permissions on my testing directory with a chmod 777 -R. After that, anyone, including the webserver, could access anything it wanted in there. Still no luck. Both scripts (testing and live) were affected, so I knew it wasn't just a weird corruption of a file, but I was still at a loss.
After a few hours cleaning and getting things ready for company as well as having some dinner, I sat down to see if I couldn't figure it out.
I scanned the blank site and noticed that the calendar said "September, 1997."
Ohhhhh.
All of my articles are time sensitive, so that I can "time bomb" the occasionally piece here and there (for example, if I pre-date a Christmas article for Dec 25, 2006, it'll show up on Winter Capitalism Day [to steal a phrase from Christin])
Since everything on the server was effectively marked "in the future," nothing at all showed up. I fixed the time, and in doing so, fixed the site.
Now I just had to reset all the permissions on my testing site.
chmod -R 664 testing
Well, that didn't work. Although the files have decent permissions, (6 - owner can read and write, 6 groups can read and write, 0 everybody else can do squat) the directories need execute permissions to let users (like the webserver) in.
I needed a way to just change the permission of the directories and their sub directories, but not the contents of those folders.
A few lines of bash scripting, and it was done.
# first find *only* directories in this dir and up to 6 subdirs.
# with the command:
# find . -mindepth 1 -maxdepth 6 -type d -print
# They will be listed with their position relative to this dir
# for example:
# ./technology/web
# which is handy for scripting
-
for i in $( find . -mindepth 1 -maxdepth 6 -type d -print ); do
-
#change the permission of every $i
#which is assigned to be the value of the condition evaluated above
#try
#echo item: $i to get a better feel for this if you're confused
#change the permissions of every directory so that apache
#(and in this case, everybody) can read its contents
chmod 777 $i
#close up the loop - for non programmers, this will repeat to the top
#until there's no more output from the "find" command above
And run it
Be careful that you'll want to run it *inside* the appropriate directory, as any directories it files will have their permissions altered. You may have to adjust the last "parent" directory by hand.




