I need to execute scp command with renaming the file.

I have tried with following code:


FILE_NAME=`echo $FILE | awk 'BEGIN{FS="/"} {print $NF;}'`

todayDateVar=`date | awk 'BEGIN{FS=" ";OFS="_"} {print $2,$3,$6;}'`


Result: (Run with ./scp.sh sample.obj)

/ngdata/nc_donotdelete/test_out_files/sample.obj.Sep_23_2014: No such file or directory

I guess this error indicates none of directory available in that name. But whenever i tried without renaming file means it works fine. The following code works fine without renaming the file.


It copied the file name as sample.obj at destination directory. But i need to copy the file with renaming.

closed as off-topic by Ulrich Schwarz, Anthon, slm Sep 23 '14 at 16:17

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Ulrich Schwarz, Anthon, slm
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    What's that sysconfig doing in your scp? Right now, you're passing three parameters: $FILE, $USERNAME…sys_config, and thirdly $DES_PATH. – Ulrich Schwarz Sep 23 '14 at 10:56
  • @UlrichSchwarz I dont know exactly. had refered from Younes ERRATI answer stackoverflow.com/questions/13451974/… – Vasu Sep 23 '14 at 11:01
  • scp command sould be scp $FILE $USERNAME:"$PASSWORD"@$HOST:$DES_PATH – Archemar Sep 23 '14 at 11:12
  • @Archemar If i change to scp $FILE $USERNAME:"$PASSWORD"@$HOST:$DES_PATH means i got ssh: ngqa: Name or service not known lost connection – Vasu Sep 23 '14 at 11:33
  • do you know you can login without a password using your public/private keys? Wouldn't it be better then having your login info stored in the script file? – smrt28 Sep 23 '14 at 11:40

If DES_PATH="/ngdata/nc_donotdelete/test_out_files/$FILE_NAME.$todayDateVar" doesn't work, and DES_PATH="/ngdata/nc_donotdelete/test_out_files" does, that means /ngdata/nc_donotdelete/test_out_files does not exist, and your file is being saved as /ngdata/nc_donotdelete/test_out_files rather than /ngdata/nc_donotdelete/test_out_files/$1 (because the target path can be either a directory or a filename, and scp will treat it as a directory only if that path exists and is already a directory or link to a directory) You can add a slash to the end of the destination path to ensure that it is always treated as a directory rather than a file.


plain password in file is a bad idea. Besides on my box I have no option -p passwd.

since you have access to remote host, you sould generate keys (private and public) using


(accept all default, do not use password)

This step should be done for every user

then, one time

ssh-copy-id ngqa@lnx25

This step should be done for every user and every host.

then in you shell, the last line sould be


Not the answer you're looking for? Browse other questions tagged or ask your own question.