Opinions/Ideas/Suggestions needed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Opinions/Ideas/Suggestions needed
# 1  
Old 01-20-2009
Opinions/Ideas/Suggestions needed

I'm currently developing a script to clean out certain directories based on age and name. Part of the assignment is to ensure that the cleaning of a directory is done under the user id of the owner (script is running as root). I have a few ideas on how to do this, but I'd like to hear your opinions/ideas/suggestions on these (maybe I've missed something):
  • Move the relevant parts into a separate script which gets called by su
  • Built a separate script in memory and pass it to su <uid> -c 'bash -c' (probably going to end in quoting ****)
  • As above, but write to a temporary location
  • ?
Ideally, I'd like a mechanism like setuid/seteuid to make a temporary privilege deescalation for a certain block, saving me the hassle of passing parameters between those scripts.
# 2  
Old 01-22-2009
I see no problem with the su method, since the only command you really need to do under that user ID is the actual rm. For efficiency make it remove many files per rm command rather than running su for each individual file (consider xargs).
# 3  
Old 01-22-2009
I probably should have been more clear, I'm sorry.

The cleaning itself isn't just a rm (that's done later, after the file has been in limbo for a specified time, and can be done as root), but include creating the target directory (if needed) and moving the file(s) there. Now in order to avoid having to call su/sudo for each and every file (and possibly creating a lot of unneeded syslog messages about the context switch) I'd like to change the user context for the whole loop.

Pseudo-Code to clarify:
Code:
loop over dirs to be cleaned
    switch user context if needed
    loop over find
        check if target exists
            otherwise create
        move file to target
        make a note of (attempted) move
    mail user the changes done and those failed
    switch back to original context

# 4  
Old 01-22-2009
I think you should as a first step enumerate all of the candidate files, sort the output into files based on file ownership like: tmp.ownername, tmp.ownername2, etc. You have to do this at some point, so do it all up front. If it is hundreds of thousands of files then "thread it" - in the sense of assign one process to one sub-directory. When all the child processes are done, then do the big sort/split.

Next, write a dynamic (one call per tmp.ownername) wrapper script that invokes the cleanup, move, etc., as a separate script with the tmp.ownername file as input. This invocation is the point at which you sudo or su, to the user as specifed by the tmp.ownername. Invoke one instance of the cleanup script per tmp.* file from the wrapper script. Again, if it is large numbers of files consider executing several cleanup scripts in the background at one shot. Only you can see the impact on other unrelated processes from all the I/O you generate doing this stuff.

I noticed cp mentioned and mv mentioned. mv is more efficient for moving files among directories within a filesystem.

Last edited by jim mcnamara; 01-22-2009 at 12:02 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Distributing script projects, suggestions/ideas?

Heyas If you recall, not too long ago, i was asking about the GNU Autotools. The feedback on that was almost unisense, and me figured that it turned my (back then) +98% SHELL project into a +73% GROFF project... :( Felt a bit overhelmed, specialy since i didnt actualy use or need the true... (0 Replies)
Discussion started by: sea
0 Replies

2. Shell Programming and Scripting

WPAR monitoring shell script suggestions needed

Hi All, This is for WPAR monitoring shell script, earlier opened thread was closed, had to open a new thread, as suggested I have used script as below, But am trying to get the output in below format, need suggestions with it. Below is the lswpar output, required output format. ... (7 Replies)
Discussion started by: aix_admin_007
7 Replies

3. Shell Programming and Scripting

Need opinions about scripting blackouts

Hi All. I am stuck and need some fresh ideas... I am writing a script that checks to see if an Oracle db is available. The script reads an ini file to determine if there is a blackout period for certain db's... ie: we don't care if it's up or down 1700 - 700 the next morning. The ini file... (3 Replies)
Discussion started by: jamie_collins
3 Replies

4. Windows & DOS: Issues & Discussions

Backing up virtual machines - opinions/suggestions needed.

Hi, I was required to do a backup of a virtual machine that runs on vmware. The guest operating system is windows, and the host is windows too. I have to backup the whole directory of the virtual machine (say in linux it'll be in /var/lib/vmware/virtual machines/) to a linux server. Initially... (0 Replies)
Discussion started by: 60doses
0 Replies

5. Shell Programming and Scripting

help/suggestions needed with wget

Hi I'm thinking of using the following command to download some music from websites I visit (designated in the mp3blogs.txt file): wget -r -l1 -H -t1 -nd -N -np -A.mp3 -erobots=off -i ~/mp3blogs.txt -P ~/Music/WGet My only question is, is there ANY way to either download files that have... (0 Replies)
Discussion started by: gMan2020
0 Replies

6. UNIX for Advanced & Expert Users

Opinions on memory increase

We are trying to tune a server which phsycially is maxed out on cpu. We are maxing out on memory and swapping at a rate of 20-43% of our swap space which is approx 45% of total ram. We "can" upgrade to twice the memory that we currently have but it will be costly as there are no more seats... (5 Replies)
Discussion started by: MizzGail
5 Replies

7. UNIX for Advanced & Expert Users

Runaway process. Opinions needed

not too long ago, i wrote a very short script that will bring up 4 customized xterms. The script went completely abnormal simply because of an error I had made in a while loop. This script took control of the system and rendered everything useless. The system admin team which i was part of... (4 Replies)
Discussion started by: TRUEST
4 Replies
Login or Register to Ask a Question