Core iTOps Tube

Thursday, 26 April 2012

Use of until loop for user confirmation

Below is my script that is using to rename the name of file .Here I am using two methods to pass the both arguments wih script name or run the script and give the input one by one.But my issue is I want to rename the name of the file if user select Y(y) then it should rename the file else select N(n) then it should exit from the script.I am using until but I think I am doing something wrong.Can you help me on this where I am wrong




Code:


ConfY_N=Y

ConfY_N=N

## Prompt Arg4

##

prompt_IM_StartDt ()

{

 echo -e "\n\nUser will enter Start Time here : ";

 read IM_StartDt;

}

##

## Set Arg4

##

set_IM_StartDt ()

{

 ## Fetching Start Date for Product Classification folder.

 IM_StartDt="";

 if [[ -z "${IM_StartDt}" ]]; then prompt_IM_StartDt; fi

}

# ----------------------------------------------------------------------------------------------------------------

## Prompt Arg5

##

prompt_IM_CloseDt ()

{

 echo -e "\n\nUser will enter Start Time here : ";

 read IM_CloseDt;

}

##

## Set Arg5

##

set_IM_CloseDt ()

{

 ## Fetching Close Date for Product Classification folder.

 IM_CloseDt="";

 if [[ -z "${IM_CloseDt}" ]]; then prompt_IM_CloseDt; fi

## Give priority to passed parameters first.

IM_StartDt="${1}";

IM_CloseDt="${2}";



#copy ()

#{

#mv ${IM_StartDt} ${IM_CloseDt}

#}

## Check arguments and set them if reqd.

## -------------------------------------

for arg in IM_StartDt:${IM_StartDt} IM_CloseDt:${IM_CloseDt};

do

  ## Get Var/Val pair

  var="${arg%:*}";

  val="${arg#*:}";

  ## Check IM variable null condition. If not set, find it from Master config file. If Master config file doesn't store the value, prompt the user (last option).

  if [[ -z "${val}" ]]; then

    set_${var};

  fi

done

#copy

until [[ $ConfY_N == "Y" ]];

do

  echo -e "\n\n\n#########################################################################################################\n";

  echo -n "- User Confirmation required, please enter (Y to continue -OR N to stop/exit gracefully): "; read ConfY_N;

               

## DONT show the below echo on Screen STDOUT. Use >>.

  ConfY_N="$(echo ${ConfY_N} | tr a-z A-Z)";

  echo -e "\n# User Selected: \"${ConfY_N}\" ####################################################################################\n\n\n";

  copy

  if [[ "${ConfY_N}" == "N" ]];

  then

      echo -e "User requested to EXIT out gracefully.\n\n";

      #echo -e "`show_script_data`";);

      exit;

      fi

done

copy ()

{

mv ${IM_StartDt} ${IM_CloseDt}

}






No comments:

Post a Comment