- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Scripting Question CIFS file moves
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-15-2007 06:27 AM
тАО08-15-2007 06:27 AM
Currently the dba's are creating PDF files with following naming conventions:
2006 - 2007_Forms_yayyaayayay.pdf
When I try to define a filename variable with in a script:
SCRIPT
#!/bin/bash
export source=/wst-tas/userdir
export dest=/wst-docs/employee
cd $source
for dirname in `ls $source`
do
for fn in `ls $dirname`
do
echo "$fn"
done
read
done
the scripts see the "2006" "-" as file names when passed as variables?
Is there a way to define the filename variable when the filename contains "spaces" in the filename from the BASH shell?
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.
Any assistance appreciated
Rex M - ESU#3 LaVista NE
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-15-2007 10:05 AM
тАО08-15-2007 10:05 AM
Solutionfor fn in ${source}/*/* ; do
d=$(echo "${fn}" | sed -e "s#${source}#${dest}#")
if [ ! -f "${d}" ] ; then
rm -f "${d}"
cp "${fn}" "${d}"
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-15-2007 10:57 AM
тАО08-15-2007 10:57 AM
Re: Scripting Question CIFS file moves
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.
So, first solution (probably the easiest):
-=-=-=-=-=-=-=-=-=-=-=-
#!/bin/bash
export SRCE=/wst-tas/userdir
export DEST=/wst-docs/employee
cd $SRCE
for FN in *
do
[ ! -f "${DEST}/${FN}" ] && /bin/cp "${FN}" $DEST/
done
-=-=-=-=-=-=-=-=-=-=-=-
Why is this the easiest? Using '*' instead of 'ls $source' keeps the file names intact even with a space in the IFS.
Using "${FN}" will ensure that the spaces within the file name are kept intact during the copy also.
The "[ -f ... ]" will check for the existance of the destination file.
If you insist in using 'ls', you should use a 'while' loop, which makes this a bit messier:
-=-=-=-=-=-=-=-=-=-=-=-
#!/bin/bash
export SRCE=/wst-tas/userdir
export DEST=/wst-docs/employee
cd $SRCE
while read FN
do
[ ! -f "${DEST}/${FN}" ] && /bin/cp "${FN}" $DEST/
done < <(/bin/ls -1 ${SRCE})
-=-=-=-=-=-=-=-=-=-=-=-
As you can see, not much difference, but you're sub-shelling out to do the 'ls'.
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.
Anyway, some things for you to think about.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-15-2007 11:27 AM
тАО08-15-2007 11:27 AM
Re: Scripting Question CIFS file moves
Here's another way to attach this:
#/usr/bin/sh
ls ${source} | while read FILE
do
cp "${FILE}" "${DESTDIR}/${FILE}"
done
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-15-2007 11:29 AM
тАО08-15-2007 11:29 AM
Re: Scripting Question CIFS file moves
Here's another way to attach this:
#/usr/bin/sh
ls ${source} | while read FILE
do
cp "${FILE}" "${DESTDIR}/${FILE}"
done
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-16-2007 01:59 AM
тАО08-16-2007 01:59 AM
Re: Scripting Question CIFS file moves
that did the trick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-16-2007 02:01 AM
тАО08-16-2007 02:01 AM