Distributing folders into set sizes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Distributing folders into set sizes
# 1  
Old 04-14-2004
Question Distributing folders into set sizes

Is it possible to have a script watch a folder which contains other folders and split the contents into folders of under 700MB?

Not sure if I explained that very well, but I have on my server an 'archive' folder where finished work is dropped, it is then burned to CD for storage and deleted, I would like to have the server automatically seperate the contents of the archive folder into folders that would fit onto a CD.

Any help / tips gratefully received.

(PS - I am new to shell scripting but not programming)
# 2  
Old 04-14-2004
i think the best approach would be do get the size of the directory.

if it exceeds the cd limits then load the files into an array and just start poping off elements of the array untill you fit the size requirements you need.

you can prolly use somethihng like perls stat to determin the filesize. or its equivelent in your programming language.

Code:
Table 29.5. Fields Returned by stat
Index Field Meaning 
0 $dev Device number of filesystem 
1 $ino Inode number 
2 $mode File mode (type and permissions) 
3 $nlink Number of (hard) links to the file 
4 $uid Numeric user ID of file's owner 
5 $gid Numeric group ID of file's designated group 
6 $rdev The device identifier (special files only) 
7 $size Total size of file, in bytes 
8 $atime Last access time in seconds since the epoch 
9 $mtime Last modify time in seconds since the epoch 
10 $ctime Inode change time (not creation time!) in seconds since the epoch 
11 $blksize Preferred blocksize for file system I/O 
12 $blocks Actual number of blocks allocated

# 3  
Old 04-15-2004
Consider using du -sk * as a basis of a korn shell script. This gives the size (in KB) of all files and directories in the current directory.
Code:
$ cd /path/to/archive
$ du -sk *
60000     archive1
55000     archive2
20000     archive3
10        myfile.txt
20        report.txt

Perhaps use two loops, one to load details of the sub-directories into an array then another to move the files into which ever has enough free space.
Code:
#!/usr/bin/ksh 

#----missing some code here to loop thru each sub-dir
#    and load the names and used space into into arrays
#----I'll just hard-code some values
dirname[0]=archive1
dirsize[0]=60000
dirname[1]=archive2
dirsize[1]=55000
#---etc

#---2nd loop: move files into archives
du -sk *|while read filesize filename
do
    #----only process plain files
    [ -f $filename ] || continue
    #----missing some code here to choose a sub-directory
    #     depending on the free space available and
    #     the size of the file.
    #----I'll just use the first one: set array index to 0
    idx=0   
    #----move file to sub-directory
    mv $filename ${dirname[$idx]}
    #----update directory array with the new size
    dirsize[$idx]=$(( ${dirsize[$idx]}+filesize ))
done

# 4  
Old 04-15-2004
Thanks for the replies, I understand what you are doing with the script, but I am not familiar with the commands, I will keep playing around with it and hopefully get it working soon.

Thanks.
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

Copy between two different folders containing same sub-folders

I have a folder like this ls input1 dir1 dir2 dir3 file1 file2 file3 dir1, dir2 and dir3 are sub-folders inside the folder input1 ls input2 dir1 dir2 dir3 file1 file2 file3 My dir1 in input1 folder has files f1, f2, f3 and f4. My dir1 in input2 folder has file f4 and f5. ... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

3. UNIX for Dummies Questions & Answers

Searching for folders/parent folders not files.

Hello again, A little while back I got help with creating a command to search all directories and sub directories for files from daystart of day x. I'm wondering if there is a command that I've overlooked that may be able to search for / write folder names to an output file which ideally... (2 Replies)
Discussion started by: Aussiemick
2 Replies

4. Shell Programming and Scripting

Making 99 folders 99 folders deep

I am trying to make a unix shell script that will make 99 folders 99 deep (counting the first level folders). So far i have made it make the first 99 folders and 99 more in all of the folders. The only problem is the only way i have found is copying and pasting part of the script over and over and... (18 Replies)
Discussion started by: YukonAppleGeek
18 Replies

5. Shell Programming and Scripting

Distributing a perl script

Hi all, I'm new to the world of Perl so may have gone about this in the wrong way (my background is mainly Java and Bash). I have a Perl script (gallery.pl) which takes in various arguments (the only mandatory arguments is a directory full of images) and creates an HTML, standards compliant... (1 Reply)
Discussion started by: forquare
1 Replies

6. UNIX for Dummies Questions & Answers

Help with distributing scripts

Hi, I have written a series of BASH scripts that I have grouped together into a software package I distribute to other users in my field. The package consists of a "master script", which users modify to specify particular processing variables. Depending on the variables specified, and their... (5 Replies)
Discussion started by: msb65
5 Replies

7. UNIX for Dummies Questions & Answers

Copying Folders without some folders... ;-)

I am in a fix....... I have to write a backup script to backup say Folder A. Folder A contains n folders 1,2 ,3 .....n. my script should copy A without folder 2 & 3. Is there anyway I can do it without writing individual copy commands???? Please help.... (5 Replies)
Discussion started by: chimpu
5 Replies
Login or Register to Ask a Question