Problem with SCP command

hi,
I am successfully running following command from command prompt

$ scp oracle@172.16.0.11:/back/crmemo.csv /sales/

but when i am running the same command from a script it copying '?' in sales (destination) folder.

Following is the script

#!/bin/sh
scp oracle@172.16.0.11:/back/crmemo.csv /sales/
echo "copied"
#

Please help me to resolve the issue :frowning:

Try with no trailing slash?

Seems like an ssh bug. ssh2 is free and more secure.

Is the target a sym link? You can try "/sales/.".

(Also,use the -d scp option =target-must-be-dir and check $? and report problems!)

I tried without trailing slash but still the same problem... get copied '?' instead of actual file...

Do you get '?' as directory entry /sales/?, or file content /sales/crmemo.csv containing '?' ? Give us a tighter handle:

ls -ld /sales/*
od -bc /sales/crmemo.csv

On executing the command
[oracle@erp sales]$ ls -ld /sales/*
-rw-rw-r-- 1 oracle oracle 166710 Nov 15 08:54 /sales/?
-------------------------------------------------------------------------------
If i run the same command from command prompt it copies the file successfully

On running same command from script I am getting following message but in sales folder i am getting '?'
crmemo.csv 100% 163KB 162.8KB/s 00:00
--------------------------------------------------------------------------------

[quote=riaz;302471629]
hi,
I am successfully running following command from command prompt

$ scp oracle@172.16.0.11:/back/crmemo.csv /sales/

but when i am running the same command from a script it copying '?' in sales (destination) folder.

Following is the script

#!/bin/sh
scp oracle@172.16.0.11:/back/crmemo.csv ./sales/
echo "copied"
#

Try using this command ie; give(./sales) it may save in the current directory :frowning:

not working.... still waiting for some solution :frowning:

How about fn to fn:

 
scp oracle@172.16.0.11:/back/crmemo.csv /sales/crmemo.csv

or turn on verbose and quote the args for stability:

 
scp -v 'oracle@172.16.0.11:/back/crmemo.csv' '/sales'

Finally, what revision of ssh?

 
ssh -V

output of script with -v scp...
---------------------------------------------------
[oracle@erp ~]$ . make_copy.sh
TEST
Executing: program /usr/bin/ssh host 172.16.0.11, user oracle, command scp -v -
/back/crmemo.csv
OpenSSH_3.9p1, OpenSSL 0.9.7a Feb 19 2003
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 172.16.0.11 [172.16.0.11] port 22.
debug1: Connection established.
debug1: identity file /home/oracle/.ssh/identity type -1
debug1: identity file /home/oracle/.ssh/id_rsa type 1
debug1: identity file /home/oracle/.ssh/id_dsa type -1
debug1: Remote protocol version 1.99, remote software version OpenSSH_3.9p1
debug1: match: OpenSSH_3.9p1 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_3.9p1
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host '172.16.0.11' is known and matches the RSA host key.
debug1: Found key in /home/oracle/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Next authentication method: gssapi-with-mic
debug1: An invalid name was supplied
Cannot determine realm for numeric host address

debug1: An invalid name was supplied
Cannot determine realm for numeric host address

debug1: Next authentication method: publickey
debug1: Trying private key: /home/oracle/.ssh/identity
debug1: Offering public key: /home/oracle/.ssh/id_rsa
debug1: Server accepts key: pkalg ssh-rsa blen 149
debug1: read PEM private key done: type RSA
debug1: Authentication succeeded (publickey).
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: Sending command: scp -v -f /back/crmemo.csv
Sending file modes: C0664 166710 crmemo.csv
Sink: C0664 166710 crmemo.csv
crmemo.csv 100% 163KB 162.8KB/s 00:00
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: channel 0: free: client-session, nchannels 1
debug1: fd 0 clearing O_NONBLOCK
debug1: fd 1 clearing O_NONBLOCK
debug1: Transferred: stdin 0, stdout 0, stderr 0 bytes in 0.1 seconds
debug1: Bytes per second: stdin 0.0, stdout 0.0, stderr 0.0
debug1: Exit status 0
copied
[oracle@erp ~]$

I see from your post that you are running the scp command as non-root and script as root.
What happens if you run the script as non-root?

I am running every thing from non root because i don't have root's password...

What happens to the file name if you copy to another directory such as /tmp?

could you post the current result of ?

cat make_copy.sh

by the way :

debug1: Sending command: scp -v -f /back/crmemo.csv

On which OS are you ? what does the -f option do ?
you should specify source and destination, i only see the sourcefile, but not the target location ...

nops, i tried to copy the file on root but same problem... getting file name as '?' but i opened the file ($ vi ?) it shows the contents of original file.

This mean i am successfully copying the file but problem is with name ....

Did you try with a specific target entryname?

It sounds like a bug in the receiving sshd. Have you checked for revisions there?