You are not logged in.

#1 2008-02-16 13:25:25

leo2501
Member
From: Buenos Aires, Argentina
Registered: 2007-07-07
Posts: 658

[help needed] make symlinks in dir to dir script for bashburn

Hi! i start using bashburn and i think is amazing! but the only thing is that to make the symlinks to /tmp/burn is tedious... i use tuxcmd and one file at the time i select from the right click menu "make symlink" for all the files i want... so i think to make an script to make symlinks from one directory to another and then when finish, delete those symlinks... BUT (BIG BUT tongue) i only want to make symlinks to /tmp/burn until it has dvd5 size (4,3gb?) adding symlinks in alfabethical order throught the original dir, because its no use if size is larger than DVD size i will need to delete those files... maybe later i can add the choose option between DVD sizes or specify a custom size tongue

Here's what i have right now, need little help & comments smile i think this will be usefull to many smile

#!/bin/bash
#
echo ' -- Make symlinks script -- '
sleep 1
##### ORIGINAL DIRECTORY #####
IDIR=pwd
echo ' Original directory: ' $IDIR
echo ' -- press c to change directory, Enter to continue -- '
read DIR
while [ "$DIR" = c ]; do
    echo ' Enter new directory path: '
    read IDIR
    echo ' New directory: ' $IDIR
    echo ' -- press c to change, Enter to continue -- '
    read DIR
done
##### DESTINATION DIRECTORY #####
echo ' Destination directory: /tmp/burn '
echo ' -- press c to change directory, Enter to continue -- '
read DIR
while [ "$DIR" = c ]; do
    echo ' Enter new directory path: '
    read FDIR
    echo ' New directory: ' $FDIR
    echo ' -- press c to change, Enter to continue -- '
    read DIR
done
##### MAKE SYMLINKS #####
for x in $IDIR
do
    ln -s $IDIR/$x $FDIR/$x
    #HERE i think need to be the directory size limit check ($size or 4,5 gb limit), dont?
done
##### SHOW CREATED SYMLINKS #####
echo Symlinks created from $IDIR to $FDIR :
ls -l $FDIR
##### KEEP OR DELETE CREATED SYMLINKS #####
echo ' -- press k to keep symlinks in ' $FDIR ', Enter to delete created symlinks in ' $FDIR ' -- '
read
for x in $ODIR ; do
    rm $x
done
echo ' symlinks in $FDIR deleted '
sleep 3
##### SHOW DESTINATION DIRECTORY #####
echo ' content of $FDIR: '
ls -l $FDIR
echo ' Press a key to exit '
read
exit 0

Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

Offline

#2 2008-02-16 14:54:13

train
Member
Registered: 2007-03-17
Posts: 38

Re: [help needed] make symlinks in dir to dir script for bashburn

Cool. I tried a bit, however -- it is not very much documented. Maybe you can use it:

#!/bin/bash
#
echo ' -- Make symlinks script -- '
sleep 1
##### ORIGINAL DIRECTORY #####
IDIR=$(pwd)
FDIR=/tmp/burn
ODIR=/tmp/other
# MAXSIZE in kbytes
MAXSIZE=$(( 120 * 1024 ))
echo $MAXSIZE
echo ' Original directory: ' $IDIR
echo ' -- press c to change directory, Enter to continue -- '
read DIR
while [ "$DIR" = c ]; do
    echo ' Enter new directory path: '
    read IDIR
    echo ' New directory: ' $IDIR
    echo ' -- press c to change, Enter to continue -- '
    read DIR
done
##### DESTINATION DIRECTORY #####
echo ' Destination directory: /tmp/burn '
echo ' -- press c to change directory, Enter to continue -- '
read DIR
while [ "$DIR" = c ]; do
    echo ' Enter new directory path: '
    read FDIR
    echo ' New directory: ' $FDIR
    echo ' -- press c to change, Enter to continue -- '
    read DIR
done
##### MAKE SYMLINKS #####
for x in $(ls -l $IDIR|grep ^d|cut -d " " -f 9)
do
    SIZE=$(du -k --max-depth=0 $IDIR/$x | cut -f 1)
    if [ $SIZE -lt $MAXSIZE ]
    then
    echo "Creating link for dir: $x  size: $SIZE"    
        ln -s $IDIR/$x $FDIR/$x
    else
    echo "Not creating link for dir: $x  size: $SIZE"
    fi
    #HERE i think need to be the directory size limit check ($size or 4,5 gb limit), dont?
done
##### SHOW CREATED SYMLINKS #####
echo Symlinks created from $IDIR to $FDIR :
ls -l $FDIR
##### KEEP OR DELETE CREATED SYMLINKS #####
echo ' -- press k to keep symlinks in ' $FDIR ', Enter to delete created symlinks in ' $FDIR ' -- '
read
for x in $ODIR ; do
    rm $x
done
echo ' symlinks in $FDIR deleted '
sleep 3
##### SHOW DESTINATION DIRECTORY #####
echo ' content of $FDIR: '
ls -l $FDIR
echo ' Press a key to exit '
read
exit 0

Offline

#3 2008-02-17 11:07:45

leo2501
Member
From: Buenos Aires, Argentina
Registered: 2007-07-07
Posts: 658

Re: [help needed] make symlinks in dir to dir script for bashburn

WOW THANKS! smile great improvement, i see now if i can make it to work like i want! smile

i dont understand really this part:

# MAXSIZE in kbytes
MAXSIZE=$(( 120 * 1024 ))
echo $MAXSIZE

because this give me 122880 but dont understand really, whit this you mean dvd size? or i need to modify it to that size?

and this:

##### MAKE SYMLINKS #####
for x in $(ls -l $IDIR|grep ^d|cut -d " " -f 9)
do

because if i run that in a directory the output is like this:

[aleyscha@aleyscha ~]$ ls -l /sda6/Movies |grep ^d|cut -d " " -f 9




[aleyscha@aleyscha ~]$

and i have a lot of movies in that dir hmm (with spaces in each filename)

Thanks in advise! this is really improving smile

Last edited by leo2501 (2008-02-17 11:14:15)


Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

Offline

#4 2008-02-17 11:29:50

leo2501
Member
From: Buenos Aires, Argentina
Registered: 2007-07-07
Posts: 658

Re: [help needed] make symlinks in dir to dir script for bashburn

I discover that if i remove the "-l" parameter in:

##### MAKE SYMLINKS #####
for x in $(ls -l $IDIR|grep ^d|cut -d " " -f 9)
do

instead of garbage i get only those filenames with no spaces, this is more like we need i think, but dont shows those filenames with spaces i get:

[aleyscha@aleyscha ~]$ ls /sda6/Movies | cut -d " " -f 9
./
../

2010.avi
300.avi


Akira.avi
Alien.avi
Animatrix.avi
Animatrix.srt


Avalon.avi
Avalon.sub

and there are files in between tha blank lines, files with spaces in his filename... and i think that the "./" and "../" filenames will be a problem, aren't? because they enter in the x variable for create a symlink to it, or they aren't?

we are getting closer tongue


Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

Offline

#5 2008-02-17 13:11:25

train
Member
Registered: 2007-03-17
Posts: 38

Re: [help needed] make symlinks in dir to dir script for bashburn

Wow, didn't thought about those things. My assumption was each DVD would have top level directories like so:

Series
Movies
Anything_else

The

 
ls -l /sda6/Movies |grep ^d|cut -d " " -f 9

does the following: It lists the contents of the Movies dir and greps for lines beginning with d like
drwx-r-xr-x ... Series
drwx-r-xr-x ... Movies
drwx-r-xr-x ... Anything_else

The cut cuts off the last part (separted by spaces -- this will separte file names with spaces.
If you have file on the toplevel this wont work.

Another command would be more appropriate:

find /sda6Movies --maxdepth=0

I think, this will give you the file list. When you do the ln you may need to add '"', like:
ln -s "$IDIR/$x" "$ODIR/$x"

The size basically calculates the total size of files in kbytes, you want on your medium. I guess for DVD it would be something like
MAX_SIZE=$(( 4 * 1024 * 1024 ))

Or put the real size in Kbytes (i think bash can't do floats like: 4.5 * 1024 * 1024)

Have fun!

Offline

Board footer

Powered by FluxBB