Type Y to Delete, if the script is being executed manually

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












This is a 2 part question.



Scenario: This script is on a cronjob. If a folder does not exist, the system sends us an email that opens a ticket which notifies us that the folder is not available. We manually have to log in and remove the preceding folder atm.



I would like for us to be able to execute the script manually and remove the preceding folder by pressing "Y" or to continue by pressing the "Enter" key, while we are logged in and execute the script manually.



This is what I have so far ...



 #-- check to see if cache folder exists
echo "Checking to see if ...";
echo "$wDir/$client%//.ftp-vendor-scripts/cache exists ... "; echo ""; >> "$log"

if [ ! -d "$wDir"/"$client%/"/.ftp-vendor-scripts/cache ]; then
echo "Directory - $wDir/$client%//.ftp-vendor-scripts/cache DOES NOT exists - Failed ..." >> "$log";

if [ ******** this script is being executed manually ******* ]; then
echo "Would you like to delete the $wDir/$client%//.ftp-vendor-scripts folder?"
echo "Press "Y" to delete the $wDir/$client%//.ftp-vendor-scripts."
echo "Press "Enter" to continue without deleting the .ftp-vendor-scripts folder."
else
echo "Directory - $wDir/$client%//.ftp-vendor-scripts/cache DOES NOT exists - Failed ..." | mail -s "$wDir/$client%//.ftp-vendor-scripts/ca$
fi

else
echo "Directory - $wDir/$client%//.ftp-vendor-scripts/cache exists - Success ..." >> "$log";
fi






share|improve this question


























    up vote
    1
    down vote

    favorite












    This is a 2 part question.



    Scenario: This script is on a cronjob. If a folder does not exist, the system sends us an email that opens a ticket which notifies us that the folder is not available. We manually have to log in and remove the preceding folder atm.



    I would like for us to be able to execute the script manually and remove the preceding folder by pressing "Y" or to continue by pressing the "Enter" key, while we are logged in and execute the script manually.



    This is what I have so far ...



     #-- check to see if cache folder exists
    echo "Checking to see if ...";
    echo "$wDir/$client%//.ftp-vendor-scripts/cache exists ... "; echo ""; >> "$log"

    if [ ! -d "$wDir"/"$client%/"/.ftp-vendor-scripts/cache ]; then
    echo "Directory - $wDir/$client%//.ftp-vendor-scripts/cache DOES NOT exists - Failed ..." >> "$log";

    if [ ******** this script is being executed manually ******* ]; then
    echo "Would you like to delete the $wDir/$client%//.ftp-vendor-scripts folder?"
    echo "Press "Y" to delete the $wDir/$client%//.ftp-vendor-scripts."
    echo "Press "Enter" to continue without deleting the .ftp-vendor-scripts folder."
    else
    echo "Directory - $wDir/$client%//.ftp-vendor-scripts/cache DOES NOT exists - Failed ..." | mail -s "$wDir/$client%//.ftp-vendor-scripts/ca$
    fi

    else
    echo "Directory - $wDir/$client%//.ftp-vendor-scripts/cache exists - Success ..." >> "$log";
    fi






    share|improve this question
























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      This is a 2 part question.



      Scenario: This script is on a cronjob. If a folder does not exist, the system sends us an email that opens a ticket which notifies us that the folder is not available. We manually have to log in and remove the preceding folder atm.



      I would like for us to be able to execute the script manually and remove the preceding folder by pressing "Y" or to continue by pressing the "Enter" key, while we are logged in and execute the script manually.



      This is what I have so far ...



       #-- check to see if cache folder exists
      echo "Checking to see if ...";
      echo "$wDir/$client%//.ftp-vendor-scripts/cache exists ... "; echo ""; >> "$log"

      if [ ! -d "$wDir"/"$client%/"/.ftp-vendor-scripts/cache ]; then
      echo "Directory - $wDir/$client%//.ftp-vendor-scripts/cache DOES NOT exists - Failed ..." >> "$log";

      if [ ******** this script is being executed manually ******* ]; then
      echo "Would you like to delete the $wDir/$client%//.ftp-vendor-scripts folder?"
      echo "Press "Y" to delete the $wDir/$client%//.ftp-vendor-scripts."
      echo "Press "Enter" to continue without deleting the .ftp-vendor-scripts folder."
      else
      echo "Directory - $wDir/$client%//.ftp-vendor-scripts/cache DOES NOT exists - Failed ..." | mail -s "$wDir/$client%//.ftp-vendor-scripts/ca$
      fi

      else
      echo "Directory - $wDir/$client%//.ftp-vendor-scripts/cache exists - Success ..." >> "$log";
      fi






      share|improve this question














      This is a 2 part question.



      Scenario: This script is on a cronjob. If a folder does not exist, the system sends us an email that opens a ticket which notifies us that the folder is not available. We manually have to log in and remove the preceding folder atm.



      I would like for us to be able to execute the script manually and remove the preceding folder by pressing "Y" or to continue by pressing the "Enter" key, while we are logged in and execute the script manually.



      This is what I have so far ...



       #-- check to see if cache folder exists
      echo "Checking to see if ...";
      echo "$wDir/$client%//.ftp-vendor-scripts/cache exists ... "; echo ""; >> "$log"

      if [ ! -d "$wDir"/"$client%/"/.ftp-vendor-scripts/cache ]; then
      echo "Directory - $wDir/$client%//.ftp-vendor-scripts/cache DOES NOT exists - Failed ..." >> "$log";

      if [ ******** this script is being executed manually ******* ]; then
      echo "Would you like to delete the $wDir/$client%//.ftp-vendor-scripts folder?"
      echo "Press "Y" to delete the $wDir/$client%//.ftp-vendor-scripts."
      echo "Press "Enter" to continue without deleting the .ftp-vendor-scripts folder."
      else
      echo "Directory - $wDir/$client%//.ftp-vendor-scripts/cache DOES NOT exists - Failed ..." | mail -s "$wDir/$client%//.ftp-vendor-scripts/ca$
      fi

      else
      echo "Directory - $wDir/$client%//.ftp-vendor-scripts/cache exists - Success ..." >> "$log";
      fi








      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 2 at 20:29









      Jeff Schaller

      31.1k846105




      31.1k846105










      asked Apr 2 at 18:48









      needtoknow

      1286




      1286




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          You need something like this:



          #!/usr/bin/env sh

          if [ -t 1 ]
          then
          interactive=1
          else
          interactive=0
          fi


          if [ "$interactive" -eq 1 ]
          then
          printf "interactiven"

          while true
          do
          printf "Rm directory? "
          read -r reply
          if [ "$reply" = "y" ]
          then
          printf "directory will be removedn"
          break
          elif [ "$reply" = "n" ]
          then
          printf "directory will not be removedn"
          break
          else
          printf "Uknown reply - it must be either y or nn"
          fi
          done

          else
          printf "non interactiven"
          fi


          The above script is POSIX-compliant and checked for errors with shellcheck. It will check if it runs in interactive or non interactive mode, possibly via cron and will act accordingly. I've tested it with bash, dash, Busybox ash and FreeBSD.






          share|improve this answer






















          • Can you adjust your script and place if [ -t 1 ]; then interactive="true"; fi at the top of the script so I can use it throughout the script? I think this is going to do us just fine.
            – needtoknow
            Apr 2 at 19:22










          • I modified the script.
            – Arkadiusz Drabczyk
            Apr 2 at 19:25










          • Hats off to you mate. I appreciatew it.
            – needtoknow
            Apr 2 at 19:27










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f435112%2ftype-y-to-delete-if-the-script-is-being-executed-manually%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          You need something like this:



          #!/usr/bin/env sh

          if [ -t 1 ]
          then
          interactive=1
          else
          interactive=0
          fi


          if [ "$interactive" -eq 1 ]
          then
          printf "interactiven"

          while true
          do
          printf "Rm directory? "
          read -r reply
          if [ "$reply" = "y" ]
          then
          printf "directory will be removedn"
          break
          elif [ "$reply" = "n" ]
          then
          printf "directory will not be removedn"
          break
          else
          printf "Uknown reply - it must be either y or nn"
          fi
          done

          else
          printf "non interactiven"
          fi


          The above script is POSIX-compliant and checked for errors with shellcheck. It will check if it runs in interactive or non interactive mode, possibly via cron and will act accordingly. I've tested it with bash, dash, Busybox ash and FreeBSD.






          share|improve this answer






















          • Can you adjust your script and place if [ -t 1 ]; then interactive="true"; fi at the top of the script so I can use it throughout the script? I think this is going to do us just fine.
            – needtoknow
            Apr 2 at 19:22










          • I modified the script.
            – Arkadiusz Drabczyk
            Apr 2 at 19:25










          • Hats off to you mate. I appreciatew it.
            – needtoknow
            Apr 2 at 19:27














          up vote
          1
          down vote



          accepted










          You need something like this:



          #!/usr/bin/env sh

          if [ -t 1 ]
          then
          interactive=1
          else
          interactive=0
          fi


          if [ "$interactive" -eq 1 ]
          then
          printf "interactiven"

          while true
          do
          printf "Rm directory? "
          read -r reply
          if [ "$reply" = "y" ]
          then
          printf "directory will be removedn"
          break
          elif [ "$reply" = "n" ]
          then
          printf "directory will not be removedn"
          break
          else
          printf "Uknown reply - it must be either y or nn"
          fi
          done

          else
          printf "non interactiven"
          fi


          The above script is POSIX-compliant and checked for errors with shellcheck. It will check if it runs in interactive or non interactive mode, possibly via cron and will act accordingly. I've tested it with bash, dash, Busybox ash and FreeBSD.






          share|improve this answer






















          • Can you adjust your script and place if [ -t 1 ]; then interactive="true"; fi at the top of the script so I can use it throughout the script? I think this is going to do us just fine.
            – needtoknow
            Apr 2 at 19:22










          • I modified the script.
            – Arkadiusz Drabczyk
            Apr 2 at 19:25










          • Hats off to you mate. I appreciatew it.
            – needtoknow
            Apr 2 at 19:27












          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          You need something like this:



          #!/usr/bin/env sh

          if [ -t 1 ]
          then
          interactive=1
          else
          interactive=0
          fi


          if [ "$interactive" -eq 1 ]
          then
          printf "interactiven"

          while true
          do
          printf "Rm directory? "
          read -r reply
          if [ "$reply" = "y" ]
          then
          printf "directory will be removedn"
          break
          elif [ "$reply" = "n" ]
          then
          printf "directory will not be removedn"
          break
          else
          printf "Uknown reply - it must be either y or nn"
          fi
          done

          else
          printf "non interactiven"
          fi


          The above script is POSIX-compliant and checked for errors with shellcheck. It will check if it runs in interactive or non interactive mode, possibly via cron and will act accordingly. I've tested it with bash, dash, Busybox ash and FreeBSD.






          share|improve this answer














          You need something like this:



          #!/usr/bin/env sh

          if [ -t 1 ]
          then
          interactive=1
          else
          interactive=0
          fi


          if [ "$interactive" -eq 1 ]
          then
          printf "interactiven"

          while true
          do
          printf "Rm directory? "
          read -r reply
          if [ "$reply" = "y" ]
          then
          printf "directory will be removedn"
          break
          elif [ "$reply" = "n" ]
          then
          printf "directory will not be removedn"
          break
          else
          printf "Uknown reply - it must be either y or nn"
          fi
          done

          else
          printf "non interactiven"
          fi


          The above script is POSIX-compliant and checked for errors with shellcheck. It will check if it runs in interactive or non interactive mode, possibly via cron and will act accordingly. I've tested it with bash, dash, Busybox ash and FreeBSD.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Apr 2 at 19:25

























          answered Apr 2 at 19:10









          Arkadiusz Drabczyk

          7,18521532




          7,18521532











          • Can you adjust your script and place if [ -t 1 ]; then interactive="true"; fi at the top of the script so I can use it throughout the script? I think this is going to do us just fine.
            – needtoknow
            Apr 2 at 19:22










          • I modified the script.
            – Arkadiusz Drabczyk
            Apr 2 at 19:25










          • Hats off to you mate. I appreciatew it.
            – needtoknow
            Apr 2 at 19:27
















          • Can you adjust your script and place if [ -t 1 ]; then interactive="true"; fi at the top of the script so I can use it throughout the script? I think this is going to do us just fine.
            – needtoknow
            Apr 2 at 19:22










          • I modified the script.
            – Arkadiusz Drabczyk
            Apr 2 at 19:25










          • Hats off to you mate. I appreciatew it.
            – needtoknow
            Apr 2 at 19:27















          Can you adjust your script and place if [ -t 1 ]; then interactive="true"; fi at the top of the script so I can use it throughout the script? I think this is going to do us just fine.
          – needtoknow
          Apr 2 at 19:22




          Can you adjust your script and place if [ -t 1 ]; then interactive="true"; fi at the top of the script so I can use it throughout the script? I think this is going to do us just fine.
          – needtoknow
          Apr 2 at 19:22












          I modified the script.
          – Arkadiusz Drabczyk
          Apr 2 at 19:25




          I modified the script.
          – Arkadiusz Drabczyk
          Apr 2 at 19:25












          Hats off to you mate. I appreciatew it.
          – needtoknow
          Apr 2 at 19:27




          Hats off to you mate. I appreciatew it.
          – needtoknow
          Apr 2 at 19:27












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f435112%2ftype-y-to-delete-if-the-script-is-being-executed-manually%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay