12-14-2008
Bash Copy-Move file problem
Hello,
I made a script to copy files from one directory to another and move file after the copy is done. When files are present in the source directory there is no problem but when no file are present I'm getting an error.
Please help !!
---------------------
#!/bin/bash
source_txt="/Users/lsimoneau/Desktop/test/pc/textes/"
destination_txt="/Users/lsimoneau/Desktop/test/destination/textes/"
archives_txt="/Users/lsimoneau/Desktop/test/z_archives_txt/"
log_txt="/Users/lsimoneau/Desktop/copietxt.log"
extenstion_txt="*.[tT][xX][tT]"
date >> $log_txt
list=`ls "$source_txt"$extenstion_txt 2> /dev/null`
old_ifs=${IFS};IFS=$' '
echo $list | echo `wc -l` "files to copy." >> $log_txt
echo $list | while read file; do
echo $file >> $log_txt
cp -f "$file" $destination_txt
mv -f "$file" $archives_txt
done
IFS=${old_ifs}
date >> $log_txt
_________
log when files are copied
Sun Dec 14 12:39:52 EST 2008
2 files to copy.
/Users/lsimoneau/Desktop/test/pc/textes/fichier01 - copie 01 09-03-47.txt
/Users/lsimoneau/Desktop/test/pc/textes/fichier01 - copie 01 09-04-59.txt
Sun Dec 14 12:39:52 EST 2008
_________
log when files are not present
Sun Dec 14 12:40:04 EST 2008
1 files to copy.
Sun Dec 14 12:40:04 EST 2008
cp: fts_open: No such file or directory
mv: rename to /Users/lsimoneau/Desktop/test/z_archives_txt/: No such file or directory
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
I am trying to create files with special characters in its filenames for testing purposes. This is on a Linux RHEL4 but this should also be applicable on a Unix shell.
I am able to create files with special characters in the filenames...e.g.
cp -pv foo.gif \*special.gif
cp -pv foo.gif \... (6 Replies)
Discussion started by: sqa777
6 Replies
2. UNIX for Dummies Questions & Answers
I am trying to move a file that is in the root directory. I suspect it is an old file created by someone when the system was installed. I am testing accessing the file by doing a copy but the command does not find the file.
I am operating as root. We are HP-UX B.11.23
I do long listing and... (3 Replies)
Discussion started by: phcorn
3 Replies
3. Shell Programming and Scripting
Hello experts,
I'm doing a shell script that able to copy or move files.
My situation is i have a drive ( lets say its S drive) where its receive all the files from mainframe
i need to copy all the file from S drive to T drive. but only those files that are finished copied from mainframe... (5 Replies)
Discussion started by: CelvinSaran
5 Replies
4. UNIX for Dummies Questions & Answers
Hello All,
i have a really strange copy paste problem. When I write some loops in an editor for example:
for j in 1 2 3
do
echo "$j"
done
and I want to paste it to the shell, the result in the shell is:
for j in 1 2 3; do e;
other commands work fine and if a copy paste... (4 Replies)
Discussion started by: creamcheese
4 Replies
5. Shell Programming and Scripting
Hi All,
I have a simple shell script to move .txt file(s) from a source directory one after another to the destination. The source directory is shared to windows using samba. The source files are arriving continuously and approx size is 10-15 KB. Some time the file size reached upto 100 KB and... (9 Replies)
Discussion started by: sraj142
9 Replies
6. Solaris
Hey everyone!. I have a problem with a file that doesn't allow any operation on it. I can't rm,mv,cp nor any other operation to it, I get the following errors:
bash-2.05# mv ora_2527.aud /bkp
mv: cannot access ora_2527.aud
bash-2.05# cp ora_2527.aud /bkp
cp: cannot access ora_2527.aud... (4 Replies)
Discussion started by: dragonov7
4 Replies
7. Shell Programming and Scripting
I'm having problems with my bash script. I would like to find a file matching today's date in the filename, i.e. my_file_20120902.txt and then move it to a different directory, i.e. /tmp. Thanks. (1 Reply)
Discussion started by: jamesi
1 Replies
8. Red Hat
Hi all,
I'm Using Centos 6.4
/opt/my_aplication/entry/data/0/
There are Thousands of files in this Directory, Only i need to copy or move the apache User's file from this to /tmp/backup , I have listed apache user's file using find . -user apache -type f , its gave me the only apache... (2 Replies)
Discussion started by: babinlonston
2 Replies
9. Shell Programming and Scripting
I have a directory /home/cmccabe/nfs/exportedReports that contains multiple folders in it. The find writes the name of each folder to out.txt. A new directory is then created in a new location /home/cmccabe/Desktop/NGS/API, named with the date. What I am trying to do, unsuccessfully at the moment,... (7 Replies)
Discussion started by: cmccabe
7 Replies
10. Shell Programming and Scripting
I am trying to mv each of the .vcf files in the variants folder to the folder in /home/cmccabe/f2 that the .vcf id is found in file. $2 in file will always have the id of a .vcf in the variants folder. The line in blue staring with R_2019 in file up to the -v5.6 will always be an exact match to a... (4 Replies)
Discussion started by: cmccabe
4 Replies
LEARN ABOUT MOJAVE
mac::morefiles5.18
MoreFiles(3) User Contributed Perl Documentation MoreFiles(3)
NAME
Mac::MoreFiles - Sophisticated file management routines
SYNOPSIS
use Mac::MoreFiles;
$application = $Application{"MrPL"};
DESCRIPTION
Variables
%Application
The %Application hash will return the path to the application for a given signature, searching on all mounted volumes.
Functions
FSpCreateMinimum SPEC
Create a new file with no creator or file type. The FSpCreateMinimum function creates a new file without attempting to set the the
creator and file type of the new file. This function is needed to create a file in an AppleShare "dropbox" where the user can make
changes, but cannot see folder or files. The FSSpec in SPEC is used to create the file.
FSpShare SPEC
Establish a local volume or directory as a share point. The FSpShare function establishes a local volume or directory as a share
point. SPEC is an FSSpec record specifying the share point.
FSpUnshare SPEC
The FSpUnshare function removes a share point in SPEC.
FSpFileCopy SRCSPEC, DSTSPEC, COPYNAME, PREFLIGHT
The FSpFileCopy function duplicates a file and optionally renames it. Since the PBHCopyFile() routine is only available on some AFP
server volumes under specific conditions, this routine either uses PBHCopyFile(), or does all of the work PBHCopyFile() does. The
SRCSPEC is used to determine the location of the file to copy. The DSTSPEC is used to determine the location of the destination
directory. If COPYNAME <> NIL, then it points to the name of the new file.
FSpDirectoryCopy SRCSPEC, DSTSPEC, PREFLIGHT, [COPYERRHANDLER]
Make a copy of a directory structure in a new location. The FSpDirectoryCopy function makes a copy of a directory structure in a new
location. COPYERRHANDLER is the Perl routine name to handle an error, should one arise. It will be called as:
$bailout = &$COPYERRHANDLER(ERRORCODE,OPERATION,SRCSPEC,DSTSPEC);
FSpIterateDirectory SPEC, MAXLEVELS, ITERATEFILTER, YOURDATAPTR
Iterate (scan) through a directory's content. The FSpIterateDirectory function performs a recursive iteration (scan) of the specified
directory and calls your ITERATEFILTER function once for each file and directory found.
The MAXLEVELS parameter lets you control how deep the recursion goes. If MAXLEVELS is 1, FSpIterateDirectory only scans the specified
directory; if MAXLEVELS is 2, FSpIterateDirectory scans the specified directory and one subdirectory below the specified directory;
etc. Set MAXLEVELS to zero to scan all levels.
The YOURDATAPTR parameter can point to whatever data structure you might want to access from within the ITERATEFILTER. Your filter
function will be called as:
$quit = &$filterFunction(YOURDATAPTR, SPEC);
FSpDTGetAPPL VOLUME, CREATOR
The FSpDTGetAPPL function finds an application (file type 'APPL') with the specified CREATOR on the specified VOLUME. It first tries to
get the application mapping from the desktop database. If that fails, then it tries to find an application with the specified creator
using the File Manager's CatSearch() routine. If that fails, then it tries to find an application in the Desktop file. Returns FSSpec
or "undef" on failure.
FSpDTSetComment SPEC, COMMENT
The FSpDTSetComment function sets a file or directory's Finder comment field. The volume must support the Desktop Manager because you
only have read access to the Desktop file.
FSpDTGetComment SPEC
The FSpDTGetComment function gets a file or directory's Finder comment field (if any) from the Desktop Manager or if the Desktop
Manager is not available, from the Finder's Desktop file. Returns Str255, or "undef" on failure.
FSpDTCopyComment SRCSPEC, DSTSPEC
The FSpDTCopyComment function copies the desktop database comment from the source to the destination object. Both the source and the
destination volumes must support the Desktop Manager.
AUTHOR
Written by Matthias Ulrich Neeracher <neeracher@mac.com>, documentation by Bob Dalgleish <bob.dalgleish@sasknet.sk.ca>. Currently
maintained by Chris Nandor <pudge@pobox.com>.
perl v5.18.2 2017-10-06 MoreFiles(3)