Script: Writing mailbox SQL record based on system users
up vote
-5
down vote
favorite
There's something wrong with this command or I'm not seeing my mistake. I also needed to exclude disabled users and users with UID over 500. This is the SQL command I need to use
INSERT INTO `mailbox` (`username`, `password`, `name`, `maildir`, `quota`, `local_part`, `domain`, `created`, `modified`, `active`) VALUES ('$username, '$pass', '', '$xxxx', 0, 'xxx', 'xxx', 'date --rfc-3339=date', 'date --rfc-3339=date', 1);"
bash shell-script kali-linux
New contributor
add a comment |
up vote
-5
down vote
favorite
There's something wrong with this command or I'm not seeing my mistake. I also needed to exclude disabled users and users with UID over 500. This is the SQL command I need to use
INSERT INTO `mailbox` (`username`, `password`, `name`, `maildir`, `quota`, `local_part`, `domain`, `created`, `modified`, `active`) VALUES ('$username, '$pass', '', '$xxxx', 0, 'xxx', 'xxx', 'date --rfc-3339=date', 'date --rfc-3339=date', 1);"
bash shell-script kali-linux
New contributor
2
Please, don't post images of text.
– Kusalananda
yesterday
2
Please take some time to write a quality question, and in particular a meaningful title. e.g. I advise avoiding simple titles "as please help me". I could also swear this is a repost.
– Rui F Ribeiro
yesterday
add a comment |
up vote
-5
down vote
favorite
up vote
-5
down vote
favorite
There's something wrong with this command or I'm not seeing my mistake. I also needed to exclude disabled users and users with UID over 500. This is the SQL command I need to use
INSERT INTO `mailbox` (`username`, `password`, `name`, `maildir`, `quota`, `local_part`, `domain`, `created`, `modified`, `active`) VALUES ('$username, '$pass', '', '$xxxx', 0, 'xxx', 'xxx', 'date --rfc-3339=date', 'date --rfc-3339=date', 1);"
bash shell-script kali-linux
New contributor
There's something wrong with this command or I'm not seeing my mistake. I also needed to exclude disabled users and users with UID over 500. This is the SQL command I need to use
INSERT INTO `mailbox` (`username`, `password`, `name`, `maildir`, `quota`, `local_part`, `domain`, `created`, `modified`, `active`) VALUES ('$username, '$pass', '', '$xxxx', 0, 'xxx', 'xxx', 'date --rfc-3339=date', 'date --rfc-3339=date', 1);"
bash shell-script kali-linux
bash shell-script kali-linux
New contributor
New contributor
edited yesterday
Kusalananda
120k16225370
120k16225370
New contributor
asked yesterday
John Doe
11
11
New contributor
New contributor
2
Please, don't post images of text.
– Kusalananda
yesterday
2
Please take some time to write a quality question, and in particular a meaningful title. e.g. I advise avoiding simple titles "as please help me". I could also swear this is a repost.
– Rui F Ribeiro
yesterday
add a comment |
2
Please, don't post images of text.
– Kusalananda
yesterday
2
Please take some time to write a quality question, and in particular a meaningful title. e.g. I advise avoiding simple titles "as please help me". I could also swear this is a repost.
– Rui F Ribeiro
yesterday
2
2
Please, don't post images of text.
– Kusalananda
yesterday
Please, don't post images of text.
– Kusalananda
yesterday
2
2
Please take some time to write a quality question, and in particular a meaningful title. e.g. I advise avoiding simple titles "as please help me". I could also swear this is a repost.
– Rui F Ribeiro
yesterday
Please take some time to write a quality question, and in particular a meaningful title. e.g. I advise avoiding simple titles "as please help me". I could also swear this is a repost.
– Rui F Ribeiro
yesterday
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
The issue is that the backticks in the SQL are treated as command substitutions by the shell. The shell would try to run backticked string as a command to replace that bit with the output of that particular command.
The shell does this because you echo
the string with double quotes.
To solve this particular issue, escape each backtick as `
.
Ideally, you would pass the SQL as a single quoted string, but that would mean that the variables wouldn't be expanded.
You can also do it this way, which would be safer:
printf 'INSERT INTO `mailbox` (`username`, `password`, `name`, `maildir`, `quota`, `local_part`, `domain`, `created`, `modified`, `active`) VALUES ("%s", "%s", "", "%s", 0, "xxx", "xxx", "date --rfc-3339=date", "date --rfc-3339=date", 1);n' "$username" "$pass" "$xxxx"
... assuming the particular database you are using can handle double quoted field data.
Kusalananda it did take the usernames and passwords and exclude the disabled users, but for each user it printed the wholeINSERT INTO mailbox ...
phrase as it is with only the usernames and passwords being filled out. What I forgot in the original question was to mention that I had written previouslyecho "INSERT INTO ..." >> test.sql
– John Doe
yesterday
@JohnDoe Well, you can redirect the output ofprintf
too...
– Kusalananda
yesterday
add a comment |
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: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
John Doe is a new contributor. Be nice, and check out our Code of Conduct.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f489294%2fscript-writing-mailbox-sql-record-based-on-system-users%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
The issue is that the backticks in the SQL are treated as command substitutions by the shell. The shell would try to run backticked string as a command to replace that bit with the output of that particular command.
The shell does this because you echo
the string with double quotes.
To solve this particular issue, escape each backtick as `
.
Ideally, you would pass the SQL as a single quoted string, but that would mean that the variables wouldn't be expanded.
You can also do it this way, which would be safer:
printf 'INSERT INTO `mailbox` (`username`, `password`, `name`, `maildir`, `quota`, `local_part`, `domain`, `created`, `modified`, `active`) VALUES ("%s", "%s", "", "%s", 0, "xxx", "xxx", "date --rfc-3339=date", "date --rfc-3339=date", 1);n' "$username" "$pass" "$xxxx"
... assuming the particular database you are using can handle double quoted field data.
Kusalananda it did take the usernames and passwords and exclude the disabled users, but for each user it printed the wholeINSERT INTO mailbox ...
phrase as it is with only the usernames and passwords being filled out. What I forgot in the original question was to mention that I had written previouslyecho "INSERT INTO ..." >> test.sql
– John Doe
yesterday
@JohnDoe Well, you can redirect the output ofprintf
too...
– Kusalananda
yesterday
add a comment |
up vote
0
down vote
The issue is that the backticks in the SQL are treated as command substitutions by the shell. The shell would try to run backticked string as a command to replace that bit with the output of that particular command.
The shell does this because you echo
the string with double quotes.
To solve this particular issue, escape each backtick as `
.
Ideally, you would pass the SQL as a single quoted string, but that would mean that the variables wouldn't be expanded.
You can also do it this way, which would be safer:
printf 'INSERT INTO `mailbox` (`username`, `password`, `name`, `maildir`, `quota`, `local_part`, `domain`, `created`, `modified`, `active`) VALUES ("%s", "%s", "", "%s", 0, "xxx", "xxx", "date --rfc-3339=date", "date --rfc-3339=date", 1);n' "$username" "$pass" "$xxxx"
... assuming the particular database you are using can handle double quoted field data.
Kusalananda it did take the usernames and passwords and exclude the disabled users, but for each user it printed the wholeINSERT INTO mailbox ...
phrase as it is with only the usernames and passwords being filled out. What I forgot in the original question was to mention that I had written previouslyecho "INSERT INTO ..." >> test.sql
– John Doe
yesterday
@JohnDoe Well, you can redirect the output ofprintf
too...
– Kusalananda
yesterday
add a comment |
up vote
0
down vote
up vote
0
down vote
The issue is that the backticks in the SQL are treated as command substitutions by the shell. The shell would try to run backticked string as a command to replace that bit with the output of that particular command.
The shell does this because you echo
the string with double quotes.
To solve this particular issue, escape each backtick as `
.
Ideally, you would pass the SQL as a single quoted string, but that would mean that the variables wouldn't be expanded.
You can also do it this way, which would be safer:
printf 'INSERT INTO `mailbox` (`username`, `password`, `name`, `maildir`, `quota`, `local_part`, `domain`, `created`, `modified`, `active`) VALUES ("%s", "%s", "", "%s", 0, "xxx", "xxx", "date --rfc-3339=date", "date --rfc-3339=date", 1);n' "$username" "$pass" "$xxxx"
... assuming the particular database you are using can handle double quoted field data.
The issue is that the backticks in the SQL are treated as command substitutions by the shell. The shell would try to run backticked string as a command to replace that bit with the output of that particular command.
The shell does this because you echo
the string with double quotes.
To solve this particular issue, escape each backtick as `
.
Ideally, you would pass the SQL as a single quoted string, but that would mean that the variables wouldn't be expanded.
You can also do it this way, which would be safer:
printf 'INSERT INTO `mailbox` (`username`, `password`, `name`, `maildir`, `quota`, `local_part`, `domain`, `created`, `modified`, `active`) VALUES ("%s", "%s", "", "%s", 0, "xxx", "xxx", "date --rfc-3339=date", "date --rfc-3339=date", 1);n' "$username" "$pass" "$xxxx"
... assuming the particular database you are using can handle double quoted field data.
answered yesterday
Kusalananda
120k16225370
120k16225370
Kusalananda it did take the usernames and passwords and exclude the disabled users, but for each user it printed the wholeINSERT INTO mailbox ...
phrase as it is with only the usernames and passwords being filled out. What I forgot in the original question was to mention that I had written previouslyecho "INSERT INTO ..." >> test.sql
– John Doe
yesterday
@JohnDoe Well, you can redirect the output ofprintf
too...
– Kusalananda
yesterday
add a comment |
Kusalananda it did take the usernames and passwords and exclude the disabled users, but for each user it printed the wholeINSERT INTO mailbox ...
phrase as it is with only the usernames and passwords being filled out. What I forgot in the original question was to mention that I had written previouslyecho "INSERT INTO ..." >> test.sql
– John Doe
yesterday
@JohnDoe Well, you can redirect the output ofprintf
too...
– Kusalananda
yesterday
Kusalananda it did take the usernames and passwords and exclude the disabled users, but for each user it printed the whole
INSERT INTO mailbox ...
phrase as it is with only the usernames and passwords being filled out. What I forgot in the original question was to mention that I had written previously echo "INSERT INTO ..." >> test.sql
– John Doe
yesterday
Kusalananda it did take the usernames and passwords and exclude the disabled users, but for each user it printed the whole
INSERT INTO mailbox ...
phrase as it is with only the usernames and passwords being filled out. What I forgot in the original question was to mention that I had written previously echo "INSERT INTO ..." >> test.sql
– John Doe
yesterday
@JohnDoe Well, you can redirect the output of
printf
too...– Kusalananda
yesterday
@JohnDoe Well, you can redirect the output of
printf
too...– Kusalananda
yesterday
add a comment |
John Doe is a new contributor. Be nice, and check out our Code of Conduct.
John Doe is a new contributor. Be nice, and check out our Code of Conduct.
John Doe is a new contributor. Be nice, and check out our Code of Conduct.
John Doe is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f489294%2fscript-writing-mailbox-sql-record-based-on-system-users%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Please, don't post images of text.
– Kusalananda
yesterday
2
Please take some time to write a quality question, and in particular a meaningful title. e.g. I advise avoiding simple titles "as please help me". I could also swear this is a repost.
– Rui F Ribeiro
yesterday