0

My shell script is working fine and the files are copying to the remote directory. However I need to check if my INPUT_STRING is starting with S and also check if the files are present in the directory before I ftp it.

#!/bin/bash
echo "Enter if the tag is present in
        Dev
        Test
        Prod
        "
while :
do
  read -r INPUT_STRING
  INPUT_STRING=`echo $INPUT_STRING | tr '[:lower:]' '[:upper:]'`
  case $INPUT_STRING in
    test | TEST)
      echo "Please enter  Tag no : "
      read -r input_variable
      if [[ ${#input_variable} -ne "7" ]]
      then
        echo "Please check the  Tag no"
        exit 1
      fi
      HOST=xxxx
      USER=xxxx
      PASSWORD=xxxx
      mypath="/path/to/$input_variable/"
      ftp -inv $HOST <<- EOF > FTPLOG
        user $USER $PASSWORD
        cd "$mypath"
        pwd
        mput x
        mput y.csv
        mput x.csv
        mput a.csv
        mput b.out
        EOF
      fgrep "550 Failed to change directory" FTPLOG >& /dev/null
      if [[ $? -eq 0 ]]
      then
        echo "File is not transfered to the  tag $input_variable. Please check the
        tag no given"
      else
        echo "File is transfered to the  tag $input_variable"
      fi
      exit 1
      ;;
    *)
      echo "Error: Invalid option..."
      exit 1
      ;;
  esac
done

1 Answer 1

1

Your case statement could look like this

S*)
                       echo Starts with S
                       if [[ -f x && -f x.csv ]]
                       then
                       echo File x and x.csv exist
                       else
                       echo input file missing
                       fi
                       ;;
3
  • Thanks Tian. can we add the validation to check if the input string is starting with S or not if [[ ${#input_variable} -ne "7" ]] Commented May 23, 2016 at 12:22
  • I think you can put this "if" inside the block of S*), and use the continue command inside it to return to the menu immediately.... Commented May 23, 2016 at 13:09
  • That's what the S*) is all about, just add this extra case after your Test case to see that this section is only executed when your input string starts with "s". Commented May 23, 2016 at 13:10

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.