LinHES Forums
http://forum.linhes.org/

Copy Linked File?
http://forum.linhes.org/viewtopic.php?f=11&t=20113
Page 1 of 1

Author:  opel70 [ Wed Jul 08, 2009 9:30 am ]
Post subject:  Copy Linked File?

Hello,

I got a new NAS box and I am looking to move some of my recordings to this location. What I would really like to do is use the /myth/pretty directory to be able to easily choose the files to move. However, I don't want to move the /myth/pretty symlink, I want to move the actual linked file.

eg:

mv (or cp) --some-switch /myth/pretty/NiceNameOfShow.mpg /myth/NASdir

The result I am looking for is to have the /myth/pretty symlink still there, but have the /myth/tv/1011.....mpg file moved (or copied) to the new location.

Is this possible? Or am I going to have to manually figure out which of the hard to decipher files in /myth/tv correspond to the many shows I want to move?

Thanks,

Author:  ceenvee703 [ Wed Jul 08, 2009 1:03 pm ]
Post subject: 

Good news for you: if you copy a file from /myth/pretty it copies the original (symlinked) file WITH the pretty name.

I regularly mount /myth/pretty and copy from that to another computer to do transcoding. That's a smb-based copy but I'm sure cp would do the same.

Someone with more Linux knowledge (i.e. just about anyone) can fill in the details about why this works, but it always has for me.

Author:  opel70 [ Wed Jul 08, 2009 1:55 pm ]
Post subject: 

Right, and I want it to copy with the un-pretty name.

Author:  ceenvee703 [ Wed Jul 08, 2009 2:56 pm ]
Post subject: 

Sorry about that. Must learn to READ posts thoroughly. :-/

Here's a thread from Ubuntu support forums that is discussing the exact solution you want. It looks like it's more involved than just a switch for cp or mv.

http://ubuntuforums.org/showthread.php?t=1104173

Author:  opel70 [ Wed Jul 08, 2009 3:10 pm ]
Post subject: 

Wow, thanks. I had tried Google searching on all sorts of words, but I guess never the right set. That looks like the exact situation I am working with. Now to parse through the thread a little bit to see how to actually get it done.

Thanks again!

Author:  opel70 [ Wed Jul 08, 2009 7:53 pm ]
Post subject: 

Thought I would come back and post my final results. Using the previously linked post, I created a "move2nas.sh" script that will take a command-line variable of the files you want to copy.
Code:
#!/bin/bash
#make sure the /myth/pretty location is up to date
su mythtv -c /usr/local/bin/mythlink.sh

#modify the IFS variable to work with file names with spaces
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")

for i in `ls /myth/pretty/$1`; do
   DESTINATION=/myth/tv3/
   RECORDING=`ls -l "$i" | grep ^l | grep "$i" | awk -F "-> " '{print $2}'`;
   echo Pretty - $i
   echo Source - "$RECORDING"
   echo Destination - $DESTINATION
   mv -v $RECORDING* "$DESTINATION"
done

#set IFS back to the default value
IFS=$SAVEIFS

So the actual usage is:
Code:
move2nas.sh CSI*

This will move all of the original files related to any TV show that starts with "CSI". to see what it would copy, you can do:
Code:
ls /myth/pretty/CSI*

This will move the actual mpg file along with any screenshot icons. Hope this is helpful to someone else. Of course you will need to modify the $DESTINATION location to suit your needs.

Author:  tjc [ Wed Jul 08, 2009 9:39 pm ]
Post subject: 

You can probably shorten that pipe used to set RECORDING using the readlink command:
Code:
RECORDING=$(readlink "$i")

Also note the use of the modern Posix $() form of back tick `` expansion. It's a lot easier to read, nests cleanly, and is generally immune to "quoting hell" problems. Highly recommended.

Author:  opel70 [ Thu Jul 09, 2009 7:34 pm ]
Post subject: 

Thanks, that part was from what I copied, so it is always nice to learn other ways to get something accomplished. And it is definitely more readable.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/