<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Scripting Question CIFS file moves in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/scripting-question-cifs-file-moves/m-p/5063169#M48937</link>
    <description>Thanks all, &lt;BR /&gt;&lt;BR /&gt;that did the trick</description>
    <pubDate>Thu, 16 Aug 2007 08:59:41 GMT</pubDate>
    <dc:creator>rmueller58</dc:creator>
    <dc:date>2007-08-16T08:59:41Z</dc:date>
    <item>
      <title>Scripting Question CIFS file moves</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-question-cifs-file-moves/m-p/5063164#M48932</link>
      <description>I have two CIFS mounts to microsoft boxes, on a linux box, &lt;BR /&gt;&lt;BR /&gt;Currently the dba's are creating PDF files with following naming conventions: &lt;BR /&gt;&lt;BR /&gt;2006 - 2007_Forms_yayyaayayay.pdf &lt;BR /&gt;&lt;BR /&gt;When I try to define a filename variable with in a script:&lt;BR /&gt;SCRIPT &lt;BR /&gt;#!/bin/bash &lt;BR /&gt;&lt;BR /&gt;export source=/wst-tas/userdir &lt;BR /&gt;export dest=/wst-docs/employee &lt;BR /&gt; &lt;BR /&gt;cd $source &lt;BR /&gt;for dirname in `ls $source` &lt;BR /&gt;&lt;BR /&gt;do &lt;BR /&gt;for fn in `ls $dirname` &lt;BR /&gt;do  &lt;BR /&gt;echo "$fn" &lt;BR /&gt;done &lt;BR /&gt;read &lt;BR /&gt;&lt;BR /&gt;done &lt;BR /&gt;&lt;BR /&gt;the scripts see the "2006" "-" as file names when passed as variables?&lt;BR /&gt;&lt;BR /&gt;Is there a way to define the filename variable when the filename contains "spaces" in the filename from the BASH shell? &lt;BR /&gt;&lt;BR /&gt;I need to copy files from $source/$EMPID to $destination/$EMPID and it the file exists in destination to ignor and go on to next file. &lt;BR /&gt;&lt;BR /&gt;Any assistance appreciated &lt;BR /&gt;&lt;BR /&gt;Rex M - ESU#3 LaVista NE</description>
      <pubDate>Wed, 15 Aug 2007 13:27:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-question-cifs-file-moves/m-p/5063164#M48932</guid>
      <dc:creator>rmueller58</dc:creator>
      <dc:date>2007-08-15T13:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting Question CIFS file moves</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-question-cifs-file-moves/m-p/5063165#M48933</link>
      <description>Any time you're using `ls foo` in a script you're almost certainly doing something wrong. You probably want something like this:&lt;BR /&gt;&lt;BR /&gt;for fn in ${source}/*/* ; do&lt;BR /&gt;d=$(echo "${fn}" | sed -e "s#${source}#${dest}#")&lt;BR /&gt;if [ ! -f "${d}" ] ; then&lt;BR /&gt;rm -f "${d}"&lt;BR /&gt;cp "${fn}" "${d}"&lt;BR /&gt;fi&lt;BR /&gt;done&lt;BR /&gt;</description>
      <pubDate>Wed, 15 Aug 2007 17:05:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-question-cifs-file-moves/m-p/5063165#M48933</guid>
      <dc:creator>Heironimus</dc:creator>
      <dc:date>2007-08-15T17:05:20Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting Question CIFS file moves</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-question-cifs-file-moves/m-p/5063166#M48934</link>
      <description>You can do quoted-strings for file names, but if you are wanting to do loops, you'll have to start messing with a few other things.&lt;BR /&gt;&lt;BR /&gt;If you want to stick with 'for' and 'ls', you'll need to mess with the 'IFS' so it doesn't treat a space as a seperator.&lt;BR /&gt;&lt;BR /&gt;So, first solution (probably the easiest):&lt;BR /&gt;&lt;BR /&gt;-=-=-=-=-=-=-=-=-=-=-=-&lt;BR /&gt;#!/bin/bash&lt;BR /&gt;export SRCE=/wst-tas/userdir&lt;BR /&gt;export DEST=/wst-docs/employee&lt;BR /&gt;&lt;BR /&gt;cd $SRCE&lt;BR /&gt;for FN in *&lt;BR /&gt;do&lt;BR /&gt;  [ ! -f "${DEST}/${FN}" ] &amp;amp;&amp;amp; /bin/cp "${FN}" $DEST/&lt;BR /&gt;done&lt;BR /&gt;-=-=-=-=-=-=-=-=-=-=-=-&lt;BR /&gt;&lt;BR /&gt;Why is this the easiest?  Using '*' instead of 'ls $source' keeps the file names intact even with a space in the IFS.&lt;BR /&gt;&lt;BR /&gt;Using "${FN}" will ensure that the spaces within the file name are kept intact during the copy also.&lt;BR /&gt;&lt;BR /&gt;The "[ -f ... ]" will check for the existance of the destination file.&lt;BR /&gt;&lt;BR /&gt;If you insist in using 'ls', you should use a 'while' loop, which makes this a bit messier:&lt;BR /&gt;&lt;BR /&gt;-=-=-=-=-=-=-=-=-=-=-=-&lt;BR /&gt;#!/bin/bash&lt;BR /&gt;export SRCE=/wst-tas/userdir&lt;BR /&gt;export DEST=/wst-docs/employee&lt;BR /&gt;&lt;BR /&gt;cd $SRCE&lt;BR /&gt;while read FN&lt;BR /&gt;do&lt;BR /&gt;  [ ! -f "${DEST}/${FN}" ] &amp;amp;&amp;amp; /bin/cp "${FN}" $DEST/&lt;BR /&gt;done &amp;lt; &amp;lt;(/bin/ls -1 ${SRCE})&lt;BR /&gt;-=-=-=-=-=-=-=-=-=-=-=-&lt;BR /&gt;&lt;BR /&gt;As you can see, not much difference, but you're sub-shelling out to do the 'ls'.&lt;BR /&gt;&lt;BR /&gt;If there are a fantastic amount of files in the directory (many many thousands), you may need to use this method, as shell environment space isn't limitless, and the '*' method expands into the current environment, where as this method uses file-descriptors to pass the list.&lt;BR /&gt;&lt;BR /&gt;Anyway, some things for you to think about.</description>
      <pubDate>Wed, 15 Aug 2007 17:57:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-question-cifs-file-moves/m-p/5063166#M48934</guid>
      <dc:creator>Stuart Browne</dc:creator>
      <dc:date>2007-08-15T17:57:32Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting Question CIFS file moves</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-question-cifs-file-moves/m-p/5063167#M48935</link>
      <description>Hi Rex:&lt;BR /&gt;&lt;BR /&gt;Here's another way to attach this:&lt;BR /&gt;&lt;BR /&gt;#/usr/bin/sh&lt;BR /&gt;ls ${source} | while read FILE&lt;BR /&gt;do&lt;BR /&gt;    cp "${FILE}" "${DESTDIR}/${FILE}"&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 15 Aug 2007 18:27:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-question-cifs-file-moves/m-p/5063167#M48935</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-08-15T18:27:44Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting Question CIFS file moves</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-question-cifs-file-moves/m-p/5063168#M48936</link>
      <description>&lt;!--!*#--&gt;Hi Rex:&lt;BR /&gt;&lt;BR /&gt;Here's another way to attach this:&lt;BR /&gt;&lt;BR /&gt;#/usr/bin/sh&lt;BR /&gt;ls ${source} | while read FILE&lt;BR /&gt;do&lt;BR /&gt;    cp "${FILE}" "${DESTDIR}/${FILE}"&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 15 Aug 2007 18:29:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-question-cifs-file-moves/m-p/5063168#M48936</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2007-08-15T18:29:32Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting Question CIFS file moves</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-question-cifs-file-moves/m-p/5063169#M48937</link>
      <description>Thanks all, &lt;BR /&gt;&lt;BR /&gt;that did the trick</description>
      <pubDate>Thu, 16 Aug 2007 08:59:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-question-cifs-file-moves/m-p/5063169#M48937</guid>
      <dc:creator>rmueller58</dc:creator>
      <dc:date>2007-08-16T08:59:41Z</dc:date>
    </item>
    <item>
      <title>Re: Scripting Question CIFS file moves</title>
      <link>https://community.hpe.com/t5/operating-system-linux/scripting-question-cifs-file-moves/m-p/5063170#M48938</link>
      <description>all items help, my script was looking at the output of a ls, i've got several scripts that work in that what, but the file names are without spaces present. The spaces screwed me up. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 16 Aug 2007 09:01:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/scripting-question-cifs-file-moves/m-p/5063170#M48938</guid>
      <dc:creator>rmueller58</dc:creator>
      <dc:date>2007-08-16T09:01:58Z</dc:date>
    </item>
  </channel>
</rss>

