0

I wrote a shell script to copy a file from Windows directory to a remote Linux machine. I'm using cygwin to run the script. The script gets executed without any error. I'm using pscp to copy files, but the file is not being copied. Putty is installed & environment variable is set.

Without putting in .sh file, the pscp command copies the files.

#!/bin/bash
logFile=/cygdrive/e/Automated/Po_transfer/po_filesfileTransfer.log 
 d=`date +%d-%m-%Y`
 t=$(date +"%T")
cd /cygdrive/e/Automated/Po_transfer/
FileName=`ls -tr|grep PO*_BV.csv >> $logFile`
pscp -pw abcd $FileName user@xxx.yy.zz.qq:/home/ckp/po
if [ $? = 0 ];
then
echo "$d  $t  $FileName transferred to Asics Factory successfully" >> $logFile
fi

The script has to copy the files to destination directory on Linux machine, but console shows:

./PO_Transfer.sh
PuTTY Secure Copy client
Release 0.70
Usage: pscp [options] [user@]host:source target
       pscp [options] source [source...] [user@]host:target
       pscp [options] -ls [user@]host:filespec
legends2k
  • 31,634
  • 25
  • 118
  • 222
mb_pravi
  • 23
  • 6
  • Can you please fix the formatting? And if you're using cygwin, why bother with `pscp` instead of the **native** `scp` with keys? – tink Jun 06 '19 at 19:35
  • on Window 16, im using the similar type of script, there the scripts works fine. – mb_pravi Jun 06 '19 at 19:42
  • That doesn't help; I have no idea what "window 16" is. And the formatting is still suboptimal. Use code tags. – tink Jun 06 '19 at 20:55
  • on Windows 16 OS , the PSCP command working fine. – mb_pravi Jun 07 '19 at 11:17
  • @tink , check to code now and please let me know why the script does not copy files to remote linux machine, whereas command `pscp -pw abcd $FileName user@xxx.yy.zz.qq:/home/ckp/po` able to copy files when ran on cgywin – mb_pravi Jun 09 '19 at 22:31
  • Impossible to know for sure, but given that `pscp` spits out a usage message I'll hazard the guess that you have files with spaces or other "odd" characters in the name that confuse the shell. Try quoting the variable. – tink Jun 09 '19 at 22:48
  • Make sure your script file is using LF only for line endings, not CRLF. Use the `dos2unix` or `d2u` or you text editor to fix the line endings. Use `cat -A PO_Transfer.sh` to check the line endings in your script file. – Doug Henderson Jun 10 '19 at 02:35
  • Hi @DougHenderson , the Script is using LF. But Dont know whats causing the issue. – mb_pravi Jun 10 '19 at 09:09
  • If the `pscp` command is a windows program, you will need to use `cygpath` to convert Unix style filenames to Windows style. E.g. `$( cygpath -w $FileName )` – Doug Henderson Jun 10 '19 at 09:22
  • Just a second there - what is the value of $FileName. Is it blank? Do you need a `| tee` after the grep? – Doug Henderson Jun 10 '19 at 09:27
  • Hi @DougHenderson , the script fixed – mb_pravi Jul 08 '19 at 17:47

0 Answers0