DaemonForums  

Go Back   DaemonForums > Miscellaneous > Programming

Programming C, bash, Python, Perl, PHP, Java, you name it.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 10th April 2010
mfaridi's Avatar
mfaridi mfaridi is offline
Spam Deminer
 
Join Date: May 2008
Location: Afghanistan
Posts: 320
Default I have 18 GB rpm packages

I have 18 GB rpm packages and I want write them on DVD with k3b ,
In each DVD I can only put 4 GB packages ,
So when I want move 4 GB in one folder and then write it , it take so long time and I have to move 4 GB packages by hand and with command , and this is so hard
I want do this with script
I need script move 4 GB of packages in folder 1 and folder 2 and ...
after this script move 4.7 GB packages is foldres , I will write them with k3b
__________________
http://www.mfaridi.com
First site about FreeBSD and OpenBSD in persian or Farsi.
Reply With Quote
  #2   (View Single Post)  
Old 10th April 2010
ephemera's Avatar
ephemera ephemera is offline
Knuth's homeboy
 
Join Date: Apr 2008
Posts: 537
Default

i suppose the sizes of the rpm files vary widely (some are small, some large...) ?

can "any" rpm file can go into "any" dvd?
Reply With Quote
  #3   (View Single Post)  
Old 10th April 2010
mfaridi's Avatar
mfaridi mfaridi is offline
Spam Deminer
 
Join Date: May 2008
Location: Afghanistan
Posts: 320
Default

Quote:
Originally Posted by ephemera View Post
i suppose the sizes of the rpm files vary widely (some are small, some large...) ?

can "any" rpm file can go into "any" dvd?
Yes , some of them are big and some of them are samll
I want only send 4 GB packages in one folder , it is not important which package go to which DVD.
__________________
http://www.mfaridi.com
First site about FreeBSD and OpenBSD in persian or Farsi.
Reply With Quote
  #4   (View Single Post)  
Old 10th April 2010
ocicat ocicat is offline
Administrator
 
Join Date: Apr 2008
Posts: 3,318
Default

Quote:
Originally Posted by mfaridi View Post
I need script ...
This is a wonderful opportunity for you to write such a script yourself. You can customize it to meet your exact needs.

As I suspect you don't know shell programming now, a good tutorial can be found at the following:

http://steve-parker.org/sh/bourne.shtml
Reply With Quote
  #5   (View Single Post)  
Old 14th April 2010
ephemera's Avatar
ephemera ephemera is offline
Knuth's homeboy
 
Join Date: Apr 2008
Posts: 537
Default

If you are looking to minimize space wastage on the dvd, then this is a bin packing problem: http://en.wikipedia.org/wiki/Bin_packing_problem

If you want something simple perhaps you try something like this:

1. Sort the rpm files in decreasing order by size.
2. Create 18GB/4GB = 5 bins (directories).
3. Pick one item off the top of the sorted list & put it into the first bin where it can fit.
4. Repeat step 3 until the list is empty.

Give it a try & don't forget to show us your script when its done. :-)
Of course, if you have any problems while writing the script you can always ask.

Last edited by ephemera; 15th April 2010 at 10:27 PM.
Reply With Quote
  #6   (View Single Post)  
Old 15th April 2010
ephemera's Avatar
ephemera ephemera is offline
Knuth's homeboy
 
Join Date: Apr 2008
Posts: 537
Default

Ok, try this:
Code:
#!/bin/sh
#
# Binpack using first fit decreasing strategy
# -ephemera

binsz=4200000       # in KB

nbins=1
b1=0
mkdir bin1
echo Processing files, please wait...
find . -type f | xargs du | sort -rn | cut -f2 | while read f
do
        n=1
        while true
        do
                eval s=\$b$n
                z=$(du $f | cut -f1)
                m=$(($s + $z))
                if [ $m -le $binsz ]; then
                        echo $(basename $f) "->" $n
                        eval mv $f bin${n}
                        eval b${n}=\${m}
                        break
                fi
                n=$(($n + 1))
                if [ $n -gt $nbins ]; then
                        eval mkdir bin${n}
                        nbins=$n
                        eval b${n}=0
                fi
        done
done
Assuming all the rpms are in one directory, 'cd' to that directory & run this script.
Once the script is done run 'ls' & see if it worked.

Last edited by ephemera; 15th April 2010 at 10:29 PM.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
packages vs ports zelut FreeBSD Ports and Packages 17 28th October 2009 08:19 AM
Can't Add Packages due to intl.4.0 jrs665 OpenBSD Packages and Ports 4 20th October 2008 10:44 AM
Packages vs. Ports guitarscn OpenBSD Packages and Ports 3 1st October 2008 04:43 AM
Where have all the packages gone? PatrickBaer FreeBSD Ports and Packages 6 12th June 2008 11:03 PM
Sorting Packages JMJ_coder NetBSD Package System (pkgsrc) 3 20th May 2008 01:08 AM


All times are GMT. The time now is 02:49 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick