Could I put this into a case script instead?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Could I put this into a case script instead?
# 1  
Old 06-25-2010
Could I put this into a case script instead?

Hi guys, I have a script which clears down a range of directories, however it can take a while to run. Is there a way I can simplify the below, perhaps adding it into a case statement?

Code:
client_directories=/usr/local/production/cleanup/bin/client_cleanups/client_directories.txt

# clear down archive directories
for client in `cat ${client_directories} | grep /archive` ;
do
        for archive in `ls -d ${client}` ;
        do
                find ${archive} -type f -mtime +13 -exec rm -f {} \; ;
        done
done

# clear down out directories
for client in `cat ${client_directories} | grep /out` ;
do
    for out in `ls -d ${client}` ;
    do
        find ${out} -type f -mtime +2 -exec mv -f {} ${out}/../archive/ \; ;
    done
done

# clear down error directories
for client in `cat ${client_directories} | grep /error` ;
do
    for error in `ls -d ${client}` ;
    do
        find ${error} -type f -mtime +13 -exec rm -f {} \; ;
    done
done

As you can see scripting isn't one of my strong points, but it gets the job done Smilie

Thanks Smilie
JayC89
# 2  
Old 06-25-2010
You may want to run the tasks in parallel ...

Code:
function kickout_1st ()
  { # clear down archive }
function kickout_2nd ()
  { # clear down out }
function kickout_3rd ()
  { # clear down error }

kickout_1st &
kickout_2nd &
kickout_3rd &

# 3  
Old 06-25-2010
as dr.house said.
and u can run rm in a seprate function at last .. u can store them in a variable and then delete all of them in 1 go....
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Where to put script to be executed before shutdown ?

Hello, My AIM is to run my script every time when someone shutdown or reboot my RHEL7 AWS instance. Query ) Where should i put my script .So, that it gets automatically executed when a server is going down or reboot ? (3 Replies)
Discussion started by: saurabh84g
3 Replies

2. Shell Programming and Scripting

Put currently running script into background

Hi All, Suppose I have a script and inside it I want/need to put it into background. I need the script to not react to SIGHUP signals. I tried: #!/bin/bash echo "" > test_disown mypid=$$ echo "PID=$mypid" ( kill -SIGSTOP $mypid jobs > myjobs #disown -h <job-spec> #kill -SIGCONT $mypid )... (6 Replies)
Discussion started by: JackK
6 Replies

3. UNIX for Dummies Questions & Answers

put script into file

hi, ok having here some code like: #!/bin/bash echo " hello " # say hello to the user echo " $HOME " echo " $HOSTNAME " echo " $(uname) " echo " today is $(date) " echo " $(whoami) is currently logged in " now my question is how to change the code so that the info is not... (12 Replies)
Discussion started by: me.
12 Replies

4. Shell Programming and Scripting

Script required to put colon

Hi Expert, I need help on script to put colon between two characters. From this line 60060160B18414009C557D9DE02CDF11 to this 60:06:01:60:B1:84:14:00:9C:55:7D:9D:E0:2C:DF:11 Any way to make it on script. (2 Replies)
Discussion started by: ranjancom2000
2 Replies

5. Solaris

how to put script in startup

Hi All, O/S: Solaris 5.10 Software installed :- Oracle 10G Weblogic 10.30 the problem i face that when the server restart for any reason SQL> exit bash-3.00# sqlplus sys/manchester as sysdba SQL*Plus: Release 10.2.0.1.0 - Production on Sun May 2 11:04:50 2010 Copyright (c)... (3 Replies)
Discussion started by: xxmasrawy
3 Replies

6. Shell Programming and Scripting

Script to Convert Upper case to Lower case

Hi All I have a script which extracts values from a Database (A persons name) and puts it into a variable in my script IE: $NAME However the Value in the DB is all in uppercase and contains the users first name and last name EG: > echo $NAME GRAHAM BOYLE > What I need is only the... (7 Replies)
Discussion started by: grahambo2005
7 Replies

7. Shell Programming and Scripting

Script is not working when put in crontab

Hi there, this is part of my script: /usr/bin/cd /u01/oradata /usr/bin/cp `/bin/ls -1 . |grep -v "^DIMStemp01.dbf$" | grep -v "^DIMSts01.dbf$"|grep -v "^DIMStects01.dbf$"` /backup It's working fine when I manually run on telnet session. /bin/ls -1 . -- to list all the files inside... (2 Replies)
Discussion started by: *Jess*
2 Replies

8. Shell Programming and Scripting

Script needed to select and delete lower case and mixed case records

HELLO ALL, URGENTLY NEEDED A SCRIPT TO SELECT AND DELETE LOWER AND MIXED CASE RECORDS FROM A COLUMN IN A TABLE. FOR EXAMPLE : Table name is EMPLOYEE and the column name is CITY and the CITY column records will be: Newyork washington ... (1 Reply)
Discussion started by: abhilash mn
1 Replies

9. UNIX for Dummies Questions & Answers

Where should I put the script?

Hi Guys, I'm a new to the UNIX. Let say I have a 1 simple script to stop and start vnc service. I want to use that script for support because my network connection to my client side is not stable and every time I have to use a long command to restart vnc. Where should I put that script?... (3 Replies)
Discussion started by: akuslive
3 Replies

10. UNIX for Dummies Questions & Answers

lower case to upper case string conversion in shell script

How can convert a Lower case variable value to an upper case in the kron shell script. (3 Replies)
Discussion started by: dchalavadi
3 Replies
Login or Register to Ask a Question