Do something if mysql command fails
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I'm trying to get the below command to do something if sql is not true
for filename in test.txt
do
mysql -N -e "SELECT ROLE FROM SENTRY WHERE ROLE = '$filename';"
exitcode=$?
if [ $exitcode -ne 0 ]; then
echo did not succeed
else
echo succeeded
fi
done
When i run this script it returns:
success
success
success
Which is not true
test.txt contains
admin
test1
test2
select role from sentry returns
admin
user
bash mysql
add a comment |Â
up vote
0
down vote
favorite
I'm trying to get the below command to do something if sql is not true
for filename in test.txt
do
mysql -N -e "SELECT ROLE FROM SENTRY WHERE ROLE = '$filename';"
exitcode=$?
if [ $exitcode -ne 0 ]; then
echo did not succeed
else
echo succeeded
fi
done
When i run this script it returns:
success
success
success
Which is not true
test.txt contains
admin
test1
test2
select role from sentry returns
admin
user
bash mysql
3
A query that returns no results is a success in mysql. You've made an assumption aboutmysql
's exit code that does not hold.
â cunninghamp3
Apr 19 at 15:32
You are right. I need to figure out a way to "if sql not true do ..."
â user3508766
Apr 19 at 15:33
I do not have the ability to hit against a mysql database at the moment, but if your query remains simple, you can most likely grab the output of the mysql command and do some logic on that, rather than the exit code.SQL_OUTPUT=$(mysql -N -e "SELECT ...")
â cunninghamp3
Apr 19 at 15:56
im in the same boat right now, server is down. I think i can just throw mysql command in a variable and then "if $mysql =="" do. I think that checks for an empty variable
â user3508766
Apr 19 at 15:59
select count(sentry.role) from . . .
and test for zero?
â siloko
Apr 19 at 16:02
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to get the below command to do something if sql is not true
for filename in test.txt
do
mysql -N -e "SELECT ROLE FROM SENTRY WHERE ROLE = '$filename';"
exitcode=$?
if [ $exitcode -ne 0 ]; then
echo did not succeed
else
echo succeeded
fi
done
When i run this script it returns:
success
success
success
Which is not true
test.txt contains
admin
test1
test2
select role from sentry returns
admin
user
bash mysql
I'm trying to get the below command to do something if sql is not true
for filename in test.txt
do
mysql -N -e "SELECT ROLE FROM SENTRY WHERE ROLE = '$filename';"
exitcode=$?
if [ $exitcode -ne 0 ]; then
echo did not succeed
else
echo succeeded
fi
done
When i run this script it returns:
success
success
success
Which is not true
test.txt contains
admin
test1
test2
select role from sentry returns
admin
user
bash mysql
asked Apr 19 at 15:27
user3508766
447
447
3
A query that returns no results is a success in mysql. You've made an assumption aboutmysql
's exit code that does not hold.
â cunninghamp3
Apr 19 at 15:32
You are right. I need to figure out a way to "if sql not true do ..."
â user3508766
Apr 19 at 15:33
I do not have the ability to hit against a mysql database at the moment, but if your query remains simple, you can most likely grab the output of the mysql command and do some logic on that, rather than the exit code.SQL_OUTPUT=$(mysql -N -e "SELECT ...")
â cunninghamp3
Apr 19 at 15:56
im in the same boat right now, server is down. I think i can just throw mysql command in a variable and then "if $mysql =="" do. I think that checks for an empty variable
â user3508766
Apr 19 at 15:59
select count(sentry.role) from . . .
and test for zero?
â siloko
Apr 19 at 16:02
add a comment |Â
3
A query that returns no results is a success in mysql. You've made an assumption aboutmysql
's exit code that does not hold.
â cunninghamp3
Apr 19 at 15:32
You are right. I need to figure out a way to "if sql not true do ..."
â user3508766
Apr 19 at 15:33
I do not have the ability to hit against a mysql database at the moment, but if your query remains simple, you can most likely grab the output of the mysql command and do some logic on that, rather than the exit code.SQL_OUTPUT=$(mysql -N -e "SELECT ...")
â cunninghamp3
Apr 19 at 15:56
im in the same boat right now, server is down. I think i can just throw mysql command in a variable and then "if $mysql =="" do. I think that checks for an empty variable
â user3508766
Apr 19 at 15:59
select count(sentry.role) from . . .
and test for zero?
â siloko
Apr 19 at 16:02
3
3
A query that returns no results is a success in mysql. You've made an assumption about
mysql
's exit code that does not hold.â cunninghamp3
Apr 19 at 15:32
A query that returns no results is a success in mysql. You've made an assumption about
mysql
's exit code that does not hold.â cunninghamp3
Apr 19 at 15:32
You are right. I need to figure out a way to "if sql not true do ..."
â user3508766
Apr 19 at 15:33
You are right. I need to figure out a way to "if sql not true do ..."
â user3508766
Apr 19 at 15:33
I do not have the ability to hit against a mysql database at the moment, but if your query remains simple, you can most likely grab the output of the mysql command and do some logic on that, rather than the exit code.
SQL_OUTPUT=$(mysql -N -e "SELECT ...")
â cunninghamp3
Apr 19 at 15:56
I do not have the ability to hit against a mysql database at the moment, but if your query remains simple, you can most likely grab the output of the mysql command and do some logic on that, rather than the exit code.
SQL_OUTPUT=$(mysql -N -e "SELECT ...")
â cunninghamp3
Apr 19 at 15:56
im in the same boat right now, server is down. I think i can just throw mysql command in a variable and then "if $mysql =="" do. I think that checks for an empty variable
â user3508766
Apr 19 at 15:59
im in the same boat right now, server is down. I think i can just throw mysql command in a variable and then "if $mysql =="" do. I think that checks for an empty variable
â user3508766
Apr 19 at 15:59
select count(sentry.role) from . . .
and test for zero?â siloko
Apr 19 at 16:02
select count(sentry.role) from . . .
and test for zero?â siloko
Apr 19 at 16:02
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Â
draft saved
draft discarded
Â
draft saved
draft discarded
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%2f438760%2fdo-something-if-mysql-command-fails%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
3
A query that returns no results is a success in mysql. You've made an assumption about
mysql
's exit code that does not hold.â cunninghamp3
Apr 19 at 15:32
You are right. I need to figure out a way to "if sql not true do ..."
â user3508766
Apr 19 at 15:33
I do not have the ability to hit against a mysql database at the moment, but if your query remains simple, you can most likely grab the output of the mysql command and do some logic on that, rather than the exit code.
SQL_OUTPUT=$(mysql -N -e "SELECT ...")
â cunninghamp3
Apr 19 at 15:56
im in the same boat right now, server is down. I think i can just throw mysql command in a variable and then "if $mysql =="" do. I think that checks for an empty variable
â user3508766
Apr 19 at 15:59
select count(sentry.role) from . . .
and test for zero?â siloko
Apr 19 at 16:02