scp error when using wildcard


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers scp error when using wildcard
# 1  
Old 12-30-2013
scp error when using wildcard

Hello,

Every time my script runs I want it to go and copy all the files from a remote server directory to my local directory. Whenever I have files in the remote directory the command
Code:
scp -p $proxy_user@$proxy_server:"$remote_dir/*" ${local_dir}

executes with 0; when I have no files in the remote directory it throws an error saying No Such File or Directory and returns >0. How can I avoid the error message if there are no files to copy? I understand I could SSH and run a command to see if there are any files to copy, but is there a way around that?

Thanks
# 2  
Old 12-30-2013
I am guessing here as I don't use scp and only use bash terminal but here goes:-
Code:
scp -p $proxy_user@$proxy_server:"$remote_dir"/* ${local_dir}

Note the quote has been shifted and /* left open...

If it does work I suspect it will transfer all subdirectories too except protected ones...

EDIT:
I have probably misread what you needed.
Just do a simple test:-
Code:
Last login: Mon Dec 30 23:56:50 on ttys000
AMIGA:barrywalker~> remote_dir="/Users/barrywalker/Empty"
AMIGA:barrywalker~> ls "$remote_dir"
AMIGA:barrywalker~> 
AMIGA:barrywalker~> ls "$remote_dir"/*
ls: /Users/barrywalker/Empty/*: No such file or directory
AMIGA:barrywalker~> ls "$remote_dir"'/*'
ls: /Users/barrywalker/Empty/*: No such file or directory
AMIGA:barrywalker~> ls "$remote_dir/*"
ls: /Users/barrywalker/Empty/*: No such file or directory
AMIGA:barrywalker~> _

The error will occur because the statment is true there is "No such file or directory"...

Last edited by wisecracker; 12-30-2013 at 08:01 PM.. Reason: See above...
# 3  
Old 12-31-2013
Code:
scp -p $proxy_user@$proxy_server:"$remote_dir"/* ${local_dir} 2>/dev/null

will keep it from sending the error to stdout but you now run the risk of not knowing whether there were no files or the command just failed unless you test the return code.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Error copying file using wildcard

Hi, cd /web/myf ls -ltr -rwxr-x--- 1 user1 Admin 17 Oct 7 15:53 mykey.db -rwxr-x--- 1 user1 Admin 21 Oct 7 15:53 test.shmore test.sh cd log01 pwd cp ../*.db .When i run the test.sh i get the below output / error. Output: /web/myf/log01 cp: cannot stat `../*.db': No such file... (5 Replies)
Discussion started by: mohtashims
5 Replies

2. AIX

Error during scp

Help needed for scp error. I tried to scp a file from a server to another with scp command, but I receive a error message "Non-Interactive Shell Disallowed!". I do not know what did I do wrong, please assist. I have done this before on other servers and have never faced this error. Both are... (2 Replies)
Discussion started by: kwliew999
2 Replies

3. UNIX for Dummies Questions & Answers

scp error while trying to copy files

Hi, I am trying to copy files from one server to other using the below code. scp -B -p user@remoteserver:/tmp/abc.txt /landing/files The above command is failing with error You're not allowed to run 'scp -p -f /tmp/abc.txt ' When I am using scp -B -p , why am I getting error msg as scp... (2 Replies)
Discussion started by: Nikhath
2 Replies

4. UNIX for Dummies Questions & Answers

SCP error: No such file or directory

Hi, I am trying to do scp using the following script: #!/usr/local/bin/bash BUILDDATE=20120220 for line in `cat arch_host_plat_src_dest` do src=`echo $line | cut -d: -f4` dest=`echo $line | cut -d: -f5` echo scp -p /builds/${BUILDDATE}/Integration/$src ... (1 Reply)
Discussion started by: Technext
1 Replies

5. UNIX for Dummies Questions & Answers

scp throws error

My script is like STAMP=$(perl -e '($ss, $mm, $hh, $DD, $MM, $YY) = localtime(time() - 100); printf "%04d%02d%02d%02d%02d", $YY + 1900, $MM + 1, $DD, $hh, $mm') touch $STAMP /sasdata/copydata/ find /sasdata/copydata -type f ! -newer /sasdata/copydata/ -print > output3.txt awk '{print "scp ... (6 Replies)
Discussion started by: tushar_spatil
6 Replies

6. Shell Programming and Scripting

Error using SCP command

Hi - I've a UNIX script which contains a scp command to copy a file to another server: scp <source path> <destination server:/path> (scp dir1/file1.dat server2:/dir1/subdir1) The job which is running this script is getting failed with error message "Remote copy Failed - Error Code: 7". When... (0 Replies)
Discussion started by: salselor
0 Replies

7. Debian

error using scp

hello fiends , i am facing this for the first time regarding the scp. when i am copying file1 from one machine to another machine in the same LAN scp file1 192.168.4.40:/root i am geting the error as /root/.bashrc: line 17: toilet: command not found /root/.bashrc: line 19: toilet:... (1 Reply)
Discussion started by: pradeepreddy
1 Replies

8. UNIX for Dummies Questions & Answers

cygwin scp script error

I'm using cygwin scp to copy a file down from a AIX server to my laptop. I've got he script working from the command line. The file I'm copying is Processed.Apr21 and I'm copying it to /event_transfer folder on my laptop. scp username@149.131.224.104:/var/Tivoli/logs/Events/processed.Apr21... (3 Replies)
Discussion started by: cav.turbo
3 Replies

9. UNIX for Dummies Questions & Answers

scp error

I am looking for a way to transfer entire folders from a Unix server to my mac OS X system. I am trying to use scp with the command % scp -r (user@host):dir . and it diesn't seem to work. I get the error "protocol error: mtime.sec not delimited" Thanks for any help. (6 Replies)
Discussion started by: lorcet222
6 Replies

10. UNIX for Dummies Questions & Answers

Find wildcard .shtml files in wildcard directories and removing them- How's it done?

I'm trying to figure out how to build a small shell script that will find old .shtml files in every /tgp/ directory on the server and delete them if they are older than 10 days... The structure of the paths are like this: /home/domains/www.domain2.com/tgp/ /home/domains/www.domain3.com/tgp/... (1 Reply)
Discussion started by: Neko
1 Replies
Login or Register to Ask a Question