From owner-freebsd-questions@FreeBSD.ORG Fri Oct 14 15:41:15 2005 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E1AF216A420 for ; Fri, 14 Oct 2005 15:41:15 +0000 (GMT) (envelope-from drew@mykitchentable.net) Received: from relay02.roc.ny.frontiernet.net (relay02.roc.ny.frontiernet.net [66.133.182.165]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5464C43D46 for ; Fri, 14 Oct 2005 15:41:14 +0000 (GMT) (envelope-from drew@mykitchentable.net) Received: from filter02.roc.ny.frontiernet.net (filter02.roc.ny.frontiernet.net [66.133.183.69]) by relay02.roc.ny.frontiernet.net (Postfix) with ESMTP id 526C737051D; Fri, 14 Oct 2005 15:41:14 +0000 (UTC) Received: from relay02.roc.ny.frontiernet.net ([66.133.182.165]) by filter02.roc.ny.frontiernet.net (filter02.roc.ny.frontiernet.net [66.133.183.69]) (amavisd-new, port 10024) with LMTP id 32066-01-13; Fri, 14 Oct 2005 15:41:14 +0000 (UTC) Received: from blacklamb.mykitchentable.net (67-51-164-214.dsl1.elk.ca.frontiernet.net [67.51.164.214]) by relay02.roc.ny.frontiernet.net (Postfix) with ESMTP id 739F33702BB; Fri, 14 Oct 2005 15:41:01 +0000 (UTC) Received: from [165.107.42.123] (unknown [165.107.42.123]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by blacklamb.mykitchentable.net (Postfix) with ESMTP id 19B381549FD; Fri, 14 Oct 2005 08:41:00 -0700 (PDT) Message-ID: <434FD118.60109@mykitchentable.net> Date: Fri, 14 Oct 2005 08:39:04 -0700 From: Drew Tomlinson User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Paul Schmehl References: <434EE80D.2010103@mykitchentable.net> <0D55CDDCD0D6445B3FF1FA6B@Paul-Schmehls-Computer.local> In-Reply-To: <0D55CDDCD0D6445B3FF1FA6B@Paul-Schmehls-Computer.local> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new-2.3.2 (20050629) at filter02.roc.ny.frontiernet.net Cc: FreeBSD Questions Subject: Re: sh Scripting - String Manipulation X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 14 Oct 2005 15:41:16 -0000 On 10/13/2005 9:03 PM Paul Schmehl wrote: > --On October 13, 2005 4:04:45 PM -0700 Drew Tomlinson > wrote: > >> I'm working on a script that reads a directory using 'find' and its >> '-exec' primary to create a symlink to the file. So for example, I have >> the following command: >> > find /multimedia/Pictures -iname "*.jpg" -print | cut -d'/' -f4 > > You'll have to play with the field value (-f) to get the right > location, but this would return only the filename. Thanks for your reply. I will look at 'cut'. Didn't know about that one. :) >> This command returns a bunch of filenames. Here's an example of one: >> >> /multimedia/Pictures/2005 Kimberly & Rich/IMG_1210.JPG >> >> What I'd like to is get '-exec' to run this command: >> > I don't understand what you're trying to do here. > >> ln -s "/multimedia/Pictures/2005 Kimberly & Rich/IMG_1210.JPG" "2005 >> Kimberly & Rich/IMG_1210.JPG" >> > Are you trying to create symlinks in a different directory? If so, > why not do this? Yes. > ln -s dir1/ dir2/ > > Then, when you add new files to dir1/ they will automatically show up > in dir2/ because the dir is symlinked rather than the individual files. That's a good idea (and something else I never thought of) if I wanted all the files, not just the *.jpg files. And as I'll explain below, I intend to expand this script to work with additional directories where I might just want the *.mp3 or the just the *.avi, *.mpg, etc. My thought was to build a script and run it through cron to keep the symlinks updated. > What exactly are you trying to accomplish? I have a FBSD 5.4 box running Samba. One of the shares on that box contains all of my pictures, video clips, and music. I have built a MythTV box on Gentoo. My first thought was to just mount the smbfs share on the Gentoo box so that MythTV could access my media files. But then I found out that MythTV needs write access to the share so it can cache thumbnails and video information. I don't want MythTV writing to my FBSD box because then it messes up other stuff that uses the same share. Thus my idea was to mount the share read-only and create symlinks to the files in a local directory on the Gentoo box. Then MythTV could write its files locally and leave the FBSD box unaltered. So specifically, I have the FBSD share mounted on the Gentoo box as /multimedia. Within the FBSD share are subdirs named Pictures, Video, and Music. Underneath these folders are many sub folders that contain the actual files. I want to make symlinks on the Gentoo box in /tv/multimedia for each of these directories but lose the subdir structure. I need to loose the subdir structure as MythTV doesn't recurse directories in some instances (specifically the MythGallery plugin). So in the above example, the Gentoo box sees "/multimedia/Pictures/2005 Kimberly & Rich/IMG_1210.JPG" as the original file mounted read-only. I want a symlink named "/tv/multimedia/2005_Kimberly_&_Rich-IMG_1210.JPG" to point to "/multimedia/Pictures/2005 Kimberly & Rich/IMG_1210.JPG". But please note that some files are more nested than the above example. Hopefully, this makes sense? But being new to scripting and knowing enough about *nix to realize there's lots of ways to accomplish any one task, I'm looking for guidance and suggestions as to the "most generally accepted" way to go about this one. :) Thanks for your time, Drew -- Visit The Alchemist's Warehouse Magic Tricks, DVDs, Videos, Books, & More! http://www.alchemistswarehouse.com