1

I need a help on my shell script. Below is my shell script which transfers the file from one server to another.

#!/bin/bash
echo "Please enter id no : "
read input_variable
echo "You entered: $input_variable"
HOST=xxxx
USER=xx
PASSWORD=xxx
ftp -inv $HOST <<EOF
user $USER $PASSWORD
cd /wpath/to/copy/files/$input_variable/inputs/final/
mput x.csv
bye
EOF

The shell script is working fine and it is copying the file X.csv once we enter id no which is present in remote server. However I have certain issues which is listed below:

  1. id no should be of 6 characters (like M000001).
  2. When I enter the correct id, the script is copying the file.However when I enter wrong id eg. M000050 which is not present in remote server, then also it is showing the file is copied. But I don't have any idea where it is copying the file.
  3. I need to create the directory /final/ if it doesn't exit in remote machine. The path till inputs will be present in remote server.

1 Answer 1

3
  1. id no should be of 6 characters (like M000001).

Something like this might do that:

if [[ ${#input_variable} != "6" ]] then
   echo "wrong length"
   exit 1
fi
  1. When I enter the correct id, the script is copying the file. However when i enter wrong id eg. M000050 which is not present in remote server, then also it is showing the file is copied. But I don't have any idea where it is copying the file.

It copies the file to the "default" ftp directory, because the cd failed, you stay in the previous directory (you can find what is the path to this directory using pwd command).

  1. I need to create the directory /final/ if it doesn't exit in remote machine. the path till inputs will be present in remote server.
mkdir /wpath/to/copy/files/$input_variable/inputs/final/

should do that

3
  • thanks very helpful. Could you please let me know which is ftp directory ? May 2, 2016 at 11:37
  • I modified the answer. pwd command should tell you where you are.
    – Jakuje
    May 2, 2016 at 11:39
  • thanks a lot..i want to create the final directory with 777 permission. I almost tried everything..do you any suggestion? May 2, 2016 at 13:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .