Hey ya’ll. I’m brand new to Ruby. Just a few hours into “Programming
Ruby” in fact. I’m loving ruby so far. I can’t wait to get into some
GTK+ with ruby (since I do a lot of GTK+ stuff in C).
I work best by solving real-world problems I have. So… an easy one…
deleting some log files on a client’s server that are over 30 days old.
These log files are named by date and time. So here’s what I have:
#-------------------------------------------------------------------------------
#! /usr/bin/env ruby
LOG_DIR = ‘/var/custom_logs/cache/’
def delete_if_old(file)
t = (Time.new-(606024*30)).strftime(“%Y%m%d_%H%M%S”).to_i
if file.to_i < t
File.delete(LOG_DIR + file)
end
end
Dir.foreach(LOG_DIR) { |f| delete_if_old f }
#-------------------------------------------------------------------------------
So, when I replace the delete with a puts, I can see that all the logic
is fine. However, when I try to delete I get a permissions error. I’m
running the script as a user that does have access to the directory and
can delete those files. So, my assumption is that ruby is NOT running as
this user (the files can ONLY be deleted by the user, not the group).
With my php scripts on this server I use cgiwrap to allow rwx access to
my scripts.
Is there anything I can do ruby-wise to allow this ruby script to delete
this file or do I have to change how the files are logged to allow group
access?
The error is something like:
… in `delete’: Operation not permitted - /var/custom_logs/cache/.
(Errno::EPERM)
Any help is appreciated. I guess I’m just trying to understand how the
script is executed… as what user. May be more of a standard linux
permissions questions but still seems odd to me that the user that’s
executing the script can delete the files but eh script itself cannot.
–
-
Micah C.
Developer - http://www.micahcarrick.com
GTK+ Forums - http://www.gtkforums.com