Type Y to Delete, if the script is being executed manually
Clash 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
bash scripting input interactive
add a comment |Â
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
bash scripting input interactive
add a comment |Â
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
bash scripting input interactive
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
bash scripting input interactive
edited Apr 2 at 20:29
Jeff Schaller
31.1k846105
31.1k846105
asked Apr 2 at 18:48
needtoknow
1286
1286
add a comment |Â
add a comment |Â
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
.
Can you adjust your script and placeif [ -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
add a comment |Â
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
.
Can you adjust your script and placeif [ -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
add a comment |Â
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
.
Can you adjust your script and placeif [ -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
add a comment |Â
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
.
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
.
edited Apr 2 at 19:25
answered Apr 2 at 19:10
Arkadiusz Drabczyk
7,18521532
7,18521532
Can you adjust your script and placeif [ -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
add a comment |Â
Can you adjust your script and placeif [ -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
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password