Click to See Complete Forum and Search --> : simple read/wrte access script
jolan_lars
04-02-2003, 05:24 AM
good day!
i'm using RH 7.2 samba as a file server and as a PDC for our small office here.
the samba shares are arranged into different folders. The folders are arranged very much like a calendar; the main folders' names are the different months (jan-dec) while the sub-folders' names are the different dates (1-31)
everyday my users put their day's work in a folder that corresponds to today's date. For example, if today is the 2nd of April, they will save it in the main folder called "april", and in a subfolder named "02".
But that is not always the case, sumtymes they erroneously put it into a differnet folder making it almost impossible to find.
what i would like to happen is, if i could just create a simple startup script that would chmod all folders to read-only except today's folder.
Since i know absolutely nothing about scripting and programming i'm turning out to you guys for help.....
Thank you very much in advance.... ;)
chrism01
04-02-2003, 10:43 AM
Try this:
#!/bin/bash
# Assume day dirs perms set to none ie
# d---------
# Get todays date in format mon dd
curr_date=`date +"%b %d"`
# Separate mth, day parts
curr_mth=`echo $curr_date|cut -d' ' -f1`
curr_day=`echo $curr_date|cut -d' ' -f2`
# Lowercase mth
curr_mth=`echo $curr_mth|tr '[A-Z]' '[a-z]'`
# debug
#echo $curr_date
#echo $curr_mth
#echo $curr_day
# Get yesterdays date in format mon dd
prev_date=`date --date="yesterday" +"%b %d"`
# Separate mth, day parts
prev_mth=`echo $prev_date|cut -d' ' -f1`
prev_day=`echo $prev_date|cut -d' ' -f2`
# Lowercase mth
prev_mth=`echo $prev_mth|tr '[A-Z]' '[a-z]'`
# debug
#echo $prev_mth
#echo $prev_day
# Now cd to dir above curr day
cd /path/to/$curr_mth
# Add all access for all users
chmod o+rwx $curr_day
# Now cd to above yesterday's dir
cd /path/to/$prev_mth
# Remove all access for all users
chmod o-rwx $prev_day
and add a line to cron
1 0 * * * /path/to/script/script.sh 1>script.log 2>&1
for root. This will run at 1 min past midnight every day.
Change values for /path/to etc and 'script' to your own values.
HTH
PS I've tested the script on my box, seems ok.
bwkaz
04-02-2003, 10:52 AM
Something like:
#!/bin/bash
chmod -R 555 /base/dir/*
month=$(date +%b)
day=$(date +%d)
chmod 775 /base/dir/$month/$day ? It'll set permissions to 555 (which is owner, group, and others, with read and execute permissions only) on everything inside /base/dir (the -R makes the chmod recursive). Then, it runs date with a couple of format arguments (%b prints out the short month, and %d prints the day of the month) and stores them in a couple of variables. Then it changes permissions on the proper directory to 775 (owner and group have read, write, and execute, and others have only read and execute). You will probably want to change these permissions, depending on who the remote users are being mapped to in Samba, and who owns the directories in question. Or you could just make the current day's directory's mode 777, to allow full access to everyone.
Save this in a script, and use cron to run it daily.
Edit: bah, that's what I get for hitting reply, then going off and reading other threads! :p
jolan_lars
04-03-2003, 05:25 AM
wow!!
thanks guys!
jolan_lars
04-03-2003, 06:18 AM
hi again....
i have a small question regarding the month notations. The folder names of the months are like whole names. i.e january, february, march, etc...
since the ouput of date +%b is only the 1st three letters, jan, feb, mar ...they won't match.
will it be possible for me to attach wildcard so that it will match?
sumthing lyk this:
chmod 775 /base/dir/$month*/$day
will the wildcard be understood?
OR
is there a simpler way to rename my folders? coz i dont' want to do it the long way....
thanks again
jolan_lars
04-03-2003, 06:21 AM
oops!
i found the command to make the months print in complete form
date +%B
thanks.....
jolan_lars
04-03-2003, 06:32 AM
i again ran into a problem:
linux prints the date with the 1st letter capitalized, my month folders are not.
Is there a way for it to match without regard to capitalization?
I hope this wont end in renaming all month folders to capital.... :(
chrism01
04-03-2003, 09:00 AM
if you notice in my code, i'm setting the month vars to lowercase before using it
:)
PS you did say jan in your orig post, that's why i used %b ;)
bwkaz
04-03-2003, 11:21 AM
Yep, use tr to lowercase all the letters in the variable.
Something like adding a line of month=$(echo $month | tr '[A-Z]' '[a-z]') before the last chmod line (if you're using my version, which it sounds like you are, since chrism01's version does this for you ;)) should work.