Script to mv files and then remove


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to mv files and then remove
# 1  
Old 09-30-2010
Script to mv files and then remove

Hi Guys i'm looking for some help with creating a scripts:

Background - I run alot of testing which creates huge files. This fills up the diskspace over 3 weeks so needs constant deleting. but generally, I keep forgetting!!! so every 3 weeks it fails lol.

Basically i can't format the drive - permissions, key files on share e.t.c. I'm looking for some way to keep the folder structure on the share and remove all the files. The remove takes a long time so i want to somehow background it so i can continue while it removes:

a script to:
  • mount shares (currently 3)
  • create a 'container folder'
  • mv files from the existing folders to the 'container folder' under folder names (leaving existing folders present but empty)
  • remove the newly created container folder with all content as a background tasks
  • the leaves existing empty folders so i can carry on running while this deletes in the background

The first share has 6 folders with files inside it and the second has 5 folders with files. The 3rd folder has only files on the share. I tried just removing "test*" of the share but when the new testing begins some of its files are removed and therefore the tests fail.

The above will mean i can then run the script and when it confirms its started deleting i can begin my new testing on the empty folders

I'v drafted up a script but it looks stupidly long and silly and i know there must be a simpler way to do it!!!

my script below:

Code:
#!/bin/sh

share1="/mnt/x"
share2="/mnt/y"
share3="/mnt/z"

printhelp()
{
	echo -e "Syntax: `basename $0` <-f foldername>"
	echo -e "  -f\tName of the folder to copy the files to"
}

mount -o vers=3,proto=tcp,noac,rsize=32768,wsize=32768 192.16.15.172:/za /mnt/x
mount -t nfs4 -o proto=tcp,noac,rsize=32768,wsize=32768 192.16.15.172:/zb /mnt/y
mount -o proto=tcp,vers=3,intr,hard,noac,wsize=16384,rsize=16384 192.16.15.171:/zc /mnt/z

mkdir -p $share1/$1/{big,deep,little,normal,small,wide}
mkdir -p $share2/$1/{big2,deep2,little2,normal2,wide2}
mkdir -p $share3/$1

chmod -R 777 $share1/$1
chmod -R 777 $share2/$1
chmod -R 777 $share3/$1

mv $share1/big/* $share1/$1/big/
mv $share1/deep/* $share1/$1/deep/
mv $share1/little/* $share1/$1/little/
mv $share1/normal/* $share1/$1/normal/
mv $share1/small/* $share1/$1/small/
mv $share1/wide/* $share1/$1/wide/

mv $share2/big2/* $share2/$1/big2/
mv $share2/deep2/* $share2/$1/deep2/
mv $share2/little2/* $share2/$1/little2/
mv $share2/normal2/* $share2/$1/normal2/
mv $share2/wide2/* $share2/$1/wide2/

mv $share3/test* $share3/$1/

rm -rf $share1/$1 &
rm -rf $share2/$1 &
rm -rf $share3/$1 &

echo "Finished!"

Hope you can help and if you need any more info.

Regards

Last edited by defamer; 09-30-2010 at 08:06 AM..
# 2  
Old 10-01-2010
Code:
It looks fine, not too many things can be simplified.

# 3  
Old 10-01-2010
------------

Last edited by Scrutinizer; 10-01-2010 at 06:11 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Script to remove backup files

HI, I want to remove my backup files keeping last 30 days. Now i am doing it manually. Does anyone have a script to automate this process? Thanks in advance (5 Replies)
Discussion started by: ElizabethPJ
5 Replies

2. UNIX for Dummies Questions & Answers

Pls. help with script to remove million files

Hi, one of the server, log directory was never cleaned up. We have so many files. I want to remove all the files that starts with dfr* but I get error message when I use the *. rm qfr* bash: /usr/bin/rm: Arg list too long I am trying to write this script but not working. ... (4 Replies)
Discussion started by: samnyc
4 Replies

3. UNIX for Dummies Questions & Answers

Script to remove zip files from a directory

Hi Folks, There is a job which generates a .zip files every day at /usr/app/generated directory , now please advise for the script that will delete this zip files permanently.but while deleting it should make sure that it will not delete the last two days recently generated zip files and this... (1 Reply)
Discussion started by: punpun66
1 Replies

4. Shell Programming and Scripting

[Validate] Script to remove files olderthan X days

Hi, I have written a small shell script to remove the files olderthan X days (say 30). But I not sure how it acts on the filesystem, as I am using rm. if then echo "##############################################" echo "Invalid no .of arguments\n" echo "Usage:\n$0 PATH... (6 Replies)
Discussion started by: karumudi7
6 Replies

5. Shell Programming and Scripting

Shell script to remove empty files

Hi All, Can anyone please write a shell script to remove the empty files using an if condition. please help me out , urgent thanks (6 Replies)
Discussion started by: muthi_murali
6 Replies

6. Shell Programming and Scripting

Shell script to remove files

I am working in directory week5 and I want to delete the files in directory week1, without leaving directory week5. I understand that rm is used to delete a file, but how do you remove them while working in a different directory. I also only want to delete a certain set of files *. (1 Reply)
Discussion started by: smiley76112
1 Replies

7. Shell Programming and Scripting

script to remove files older than 60 days

Hi I need help in the script which looks at a contorl file which has a list of file names like xxxx.12345 and I want to take only xxxxx and search in a specific directory and remove the file if its older than 60 days I have written something like this.. but seems to be wrong... (1 Reply)
Discussion started by: antointoronto
1 Replies

8. Shell Programming and Scripting

Script to remove all empty files within the directory structure?

Hi I need to write a shell script which basically searches for all the empty files within the directory structure, lists them before asking the user to confirm if they would like to delete them. If the user deletes the file then a notice would appear confirming the file is deleted. I've be... (5 Replies)
Discussion started by: cat123
5 Replies

9. Shell Programming and Scripting

Script to remove log files

Can anyone help me with a shell script to remove all files (log files) created 7 days before current system date. TIA, Kiran. (1 Reply)
Discussion started by: kiranherekar
1 Replies
Login or Register to Ask a Question