Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Linux and Unix
Tag Cloud
access acer asus bios bsod computer crash desktop driver drivers error ethernet excel freeze gaming hard drive hardware hdmi internet laptop malware memory modem monitor motherboard network printer problem ram registry router security slow software sound toshiba trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > Linux and Unix >
Solved: sh copy troubles

Reply  
Thread Tools
cpscdave's Avatar
Member with 399 posts.
 
Join Date: Feb 2004
Experience: Intermediate
06-Dec-2007, 11:29 AM #1
Solved: sh copy troubles
Hi all,
I have a sh script to copy 15k files from various driectories into 1 directory but it isnt working.

In the sh I have:
Code:
#!/bin/sh
echo copying files
cp /data/production/101866/310659.pdf /data2/PublicCalgary/CPT_90-_Portfolio_Crystallization/Statements/Nov_30th/I5
echo copy1 done
I added the echos to see if it was dieing on the copy and it isnt as it outputs both echo's. But no files get copied.
If I copy a line from the script and put it in manually it works and moves the files.
Whats going on??
(running the script as root so shouldnt be permissions)

Thanks
__________________
Its not a bug.... Its a feature!

Programming today is a race between software engineers striving to build bigger and better idiot-proof
programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
-Rick Cook
RobLinux's Avatar
Computer Specs
Member with 417 posts.
 
Join Date: Nov 2007
Location: UK
Experience: UNIX/Linux Pro, M$ 'doze Sufferer
06-Dec-2007, 12:23 PM #2
Try "set -x" in shell script when you debug.

Now have a look at what rsync(1) does, it's rather neat. I like "rsync -cSHax" for backup, which with "-essh" option works from one machine to another, and if you like verbosity "-v".

Is "/data2/PublicCalgary/CPT_90-_Portfolio_Crystallization/Statements/Nov_30th/I5" a directory or a file? If it's a file then it is 310659.pdf, try cmp(1) to check on that.

To check whether commands suceed, $? should be 0, if it's not then some error occured, real programs should check this. You can use the && and || operators to have convenient conditionals. A pattern like :

foo && {
echo Success!
bar
}

or/

foo || {
echo Abandoning due to foo failing
exit 1
}

Or...

case $? in
0)
# Succeeded
;;
*)
# Uh oh!!
;;
esac

May also be useful, I use case for historical reasons and generaliity but there's a "test" command and if as well. case used to be more efficient, but still is more general.

Last edited by RobLinux; 06-Dec-2007 at 12:30 PM..
lotuseclat79's Avatar
Distinguished Member with 21,345 posts.
 
Join Date: Sep 2003
Location: -71.45091, 42.27841
06-Dec-2007, 12:35 PM #3
Quote:
Originally Posted by cpscdave
Hi all,
I have a sh script to copy 15k files from various driectories into 1 directory but it isnt working.

In the sh I have:
Code:
#!/bin/sh
echo copying files
cp /data/production/101866/310659.pdf /data2/PublicCalgary/CPT_90-_Portfolio_Crystallization/Statements/Nov_30th/I5
echo copy1 done
I added the echos to see if it was dieing on the copy and it isnt as it outputs both echo's. But no files get copied.
If I copy a line from the script and put it in manually it works and moves the files.
Whats going on??
(running the script as root so shouldnt be permissions)

Thanks
Hi cpscdave,

If the second argument to the cp command is NOT a directory, i.e. .../Nov_30th/I5,
then the first argument to the cp command will be copied to a file by the name of I5 in the .../Nov_30th directory, otherwise the .pdf file shoule have copied to the I5 directory.

cd to the Nov_30th directory and issue the command: file I5
or issue the command: ls -ldt I5
to find out if the .pdf file got copied or that I5 is indeed a directory where you should be able to find the .pdf file.

You might just find out that the I5 directory did not exist and all you have to do is rename I5 to the name of the .pdf file by issuing the command:
$ mv I5 310659.pdf
in the .../Nov_30th/ directory, but only if you found out that I5 was a file, and not a directory.

-- Tom
__________________
The independence created by philosophical insight is - in my opinion - the mark of distinction
between a mere artisan or specialist and a real seeker after truth. - Einstein 1944
Imagination is more important than knowledge. - Einstein
cpscdave's Avatar
Member with 399 posts.
 
Join Date: Feb 2004
Experience: Intermediate
06-Dec-2007, 01:19 PM #4
lol ya no .../I5 is a directory.

This is trying to copy files to a samba share not sure if that woudl make a difference

I added the || { echo failed exit 1} to the first copy and it is dieing. Just not sure why. It doesnt say why its failing.

I think I might just have to write a php script to move the files for me but I'd stll like to know why its not working. GRRRRRRRRR
__________________
Its not a bug.... Its a feature!

Programming today is a race between software engineers striving to build bigger and better idiot-proof
programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
-Rick Cook
cpscdave's Avatar
Member with 399 posts.
 
Join Date: Feb 2004
Experience: Intermediate
06-Dec-2007, 01:56 PM #5
If you heard a large bang bang bang a little while ago. Dont be concerned. It was just me BASHING my head on the wall.

The process I used was:
Exported the list of files I needed to copy from phpMyAdmin into a textfile
did a macro replace in xemacs (ON WINDOWS)
pscp'd the file to unix server and tried to run it.

Works great except of the fact windows puts in \r\n instead of just \n.

so when I ran the script it was trying to copy to .../I5\r/

boy do I feel dumb
__________________
Its not a bug.... Its a feature!

Programming today is a race between software engineers striving to build bigger and better idiot-proof
programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
-Rick Cook
lotuseclat79's Avatar
Distinguished Member with 21,345 posts.
 
Join Date: Sep 2003
Location: -71.45091, 42.27841
07-Dec-2007, 02:01 PM #6
Quote:
Originally Posted by cpscdave
lol ya no .../I5 is a directory.

This is trying to copy files to a samba share not sure if that woudl make a difference

I added the || { echo failed exit 1} to the first copy and it is dieing. Just not sure why. It doesnt say why its failing.

I think I might just have to write a php script to move the files for me but I'd stll like to know why its not working. GRRRRRRRRR
Not sure, but since you are working between shares, you might need to use the rcp command rather than the cp command. Also, between systems it is common in Linux/Unix to address the remote system with a hostname:/directorypath. I don't know if this is the same using Samba or not since I have not used it, but it surely works between Linux/Unix systems over a network.

Give rcp a shot to see what happens anyway. Least that can happen is it still won't work.

-- Tom
__________________
The independence created by philosophical insight is - in my opinion - the mark of distinction
between a mere artisan or specialist and a real seeker after truth. - Einstein 1944
Imagination is more important than knowledge. - Einstein
RobLinux's Avatar
Computer Specs
Member with 417 posts.
 
Join Date: Nov 2007
Location: UK
Experience: UNIX/Linux Pro, M$ 'doze Sufferer
07-Dec-2007, 04:06 PM #7
If the file system is mounted and your machine is a client, it is a file, accessed in normal way, so cp should be fine. The filesystem has to take care of things like POSIX permissions and any attributes that the foreign filesystem may not grok properly.
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 10:02 PM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.