Script: Writing mailbox SQL record based on system users
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
add a comment |
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
2
Please, don't post images of text.
– Kusalananda
Dec 16 at 12:59
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
Dec 16 at 14:04
add a comment |
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
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
edited Dec 16 at 12:55
Kusalananda
121k16229372
121k16229372
asked Dec 16 at 12:41
John Doe
11
11
2
Please, don't post images of text.
– Kusalananda
Dec 16 at 12:59
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
Dec 16 at 14:04
add a comment |
2
Please, don't post images of text.
– Kusalananda
Dec 16 at 12:59
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
Dec 16 at 14:04
2
2
Please, don't post images of text.
– Kusalananda
Dec 16 at 12:59
Please, don't post images of text.
– Kusalananda
Dec 16 at 12:59
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
Dec 16 at 14:04
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
Dec 16 at 14:04
add a comment |
1 Answer
1
active
oldest
votes
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
Dec 16 at 13:16
@JohnDoe Well, you can redirect the output ofprintf
too...
– Kusalananda
Dec 16 at 13:39
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',
autoActivateHeartbeat: false,
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
});
}
});
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
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
Dec 16 at 13:16
@JohnDoe Well, you can redirect the output ofprintf
too...
– Kusalananda
Dec 16 at 13:39
add a comment |
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
Dec 16 at 13:16
@JohnDoe Well, you can redirect the output ofprintf
too...
– Kusalananda
Dec 16 at 13:39
add a comment |
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 Dec 16 at 12:54
Kusalananda
121k16229372
121k16229372
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
Dec 16 at 13:16
@JohnDoe Well, you can redirect the output ofprintf
too...
– Kusalananda
Dec 16 at 13:39
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
Dec 16 at 13:16
@JohnDoe Well, you can redirect the output ofprintf
too...
– Kusalananda
Dec 16 at 13:39
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
Dec 16 at 13:16
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
Dec 16 at 13:16
@JohnDoe Well, you can redirect the output of
printf
too...– Kusalananda
Dec 16 at 13:39
@JohnDoe Well, you can redirect the output of
printf
too...– Kusalananda
Dec 16 at 13:39
add a comment |
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
Dec 16 at 12:59
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
Dec 16 at 14:04