Alert or execute script, only if config file shows not in production mode
I would like to test the software in development by running a particular script, say script file.ext
. But I was told that I an not allowed to run the script if a config file, say file.conf
, contains a particular string (not a comment with a leading #) which states the system is in production mode.
So in bash, how can I do something like
If file1.conf
contain a string in production
and that string is is not of the form something ... # something in production something
then execute script file1.ext
.
Or, can I somehow get an alert every time the designated file contains the string in production
, not in a comment?
I guess I need somehow use the command inotifywait
. It would be also nice to have a script that not only checks the file file1.conf
but alerts every time that some file with extension .conf
shows I'm in a production mode.
bash inotify
add a comment |
I would like to test the software in development by running a particular script, say script file.ext
. But I was told that I an not allowed to run the script if a config file, say file.conf
, contains a particular string (not a comment with a leading #) which states the system is in production mode.
So in bash, how can I do something like
If file1.conf
contain a string in production
and that string is is not of the form something ... # something in production something
then execute script file1.ext
.
Or, can I somehow get an alert every time the designated file contains the string in production
, not in a comment?
I guess I need somehow use the command inotifywait
. It would be also nice to have a script that not only checks the file file1.conf
but alerts every time that some file with extension .conf
shows I'm in a production mode.
bash inotify
add a comment |
I would like to test the software in development by running a particular script, say script file.ext
. But I was told that I an not allowed to run the script if a config file, say file.conf
, contains a particular string (not a comment with a leading #) which states the system is in production mode.
So in bash, how can I do something like
If file1.conf
contain a string in production
and that string is is not of the form something ... # something in production something
then execute script file1.ext
.
Or, can I somehow get an alert every time the designated file contains the string in production
, not in a comment?
I guess I need somehow use the command inotifywait
. It would be also nice to have a script that not only checks the file file1.conf
but alerts every time that some file with extension .conf
shows I'm in a production mode.
bash inotify
I would like to test the software in development by running a particular script, say script file.ext
. But I was told that I an not allowed to run the script if a config file, say file.conf
, contains a particular string (not a comment with a leading #) which states the system is in production mode.
So in bash, how can I do something like
If file1.conf
contain a string in production
and that string is is not of the form something ... # something in production something
then execute script file1.ext
.
Or, can I somehow get an alert every time the designated file contains the string in production
, not in a comment?
I guess I need somehow use the command inotifywait
. It would be also nice to have a script that not only checks the file file1.conf
but alerts every time that some file with extension .conf
shows I'm in a production mode.
bash inotify
bash inotify
edited Mar 4 at 19:08
K7AAY
814926
814926
asked Mar 4 at 16:23
juniorprogrammerjuniorprogrammer
132
132
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
One way to achieve this is with grep
, e.g.,
grep "^[^#]* in production " file.conf || script file.ext
The part behind the ||
is only executed if the part before it does not exist with exit code 0 and grep
has exit code 0 only if it finds its pattern (the first argument).
I chose a simple pattern "^[^#]* in production "
. The character ^
stands for the beginning of the line, [^#]
stands for any char except #
and the quantifier *
says there can be any number of them. The rest of the pattern is just the text you would expect to mark production mode.
In order to avoid all the output grep
is producing you can send it to /dev/null
:
grep "^[^#]* in production " file.conf > /dev/null || script file.ext
If you want to print a message, if you are in production mode and the script is not run you could do
grep "^[^#]* in production " file.conf > /dev/null &&
echo "We are in production mode. The script was not run." ||
script file.ext
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%2f504297%2falert-or-execute-script-only-if-config-file-shows-not-in-production-mode%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
One way to achieve this is with grep
, e.g.,
grep "^[^#]* in production " file.conf || script file.ext
The part behind the ||
is only executed if the part before it does not exist with exit code 0 and grep
has exit code 0 only if it finds its pattern (the first argument).
I chose a simple pattern "^[^#]* in production "
. The character ^
stands for the beginning of the line, [^#]
stands for any char except #
and the quantifier *
says there can be any number of them. The rest of the pattern is just the text you would expect to mark production mode.
In order to avoid all the output grep
is producing you can send it to /dev/null
:
grep "^[^#]* in production " file.conf > /dev/null || script file.ext
If you want to print a message, if you are in production mode and the script is not run you could do
grep "^[^#]* in production " file.conf > /dev/null &&
echo "We are in production mode. The script was not run." ||
script file.ext
add a comment |
One way to achieve this is with grep
, e.g.,
grep "^[^#]* in production " file.conf || script file.ext
The part behind the ||
is only executed if the part before it does not exist with exit code 0 and grep
has exit code 0 only if it finds its pattern (the first argument).
I chose a simple pattern "^[^#]* in production "
. The character ^
stands for the beginning of the line, [^#]
stands for any char except #
and the quantifier *
says there can be any number of them. The rest of the pattern is just the text you would expect to mark production mode.
In order to avoid all the output grep
is producing you can send it to /dev/null
:
grep "^[^#]* in production " file.conf > /dev/null || script file.ext
If you want to print a message, if you are in production mode and the script is not run you could do
grep "^[^#]* in production " file.conf > /dev/null &&
echo "We are in production mode. The script was not run." ||
script file.ext
add a comment |
One way to achieve this is with grep
, e.g.,
grep "^[^#]* in production " file.conf || script file.ext
The part behind the ||
is only executed if the part before it does not exist with exit code 0 and grep
has exit code 0 only if it finds its pattern (the first argument).
I chose a simple pattern "^[^#]* in production "
. The character ^
stands for the beginning of the line, [^#]
stands for any char except #
and the quantifier *
says there can be any number of them. The rest of the pattern is just the text you would expect to mark production mode.
In order to avoid all the output grep
is producing you can send it to /dev/null
:
grep "^[^#]* in production " file.conf > /dev/null || script file.ext
If you want to print a message, if you are in production mode and the script is not run you could do
grep "^[^#]* in production " file.conf > /dev/null &&
echo "We are in production mode. The script was not run." ||
script file.ext
One way to achieve this is with grep
, e.g.,
grep "^[^#]* in production " file.conf || script file.ext
The part behind the ||
is only executed if the part before it does not exist with exit code 0 and grep
has exit code 0 only if it finds its pattern (the first argument).
I chose a simple pattern "^[^#]* in production "
. The character ^
stands for the beginning of the line, [^#]
stands for any char except #
and the quantifier *
says there can be any number of them. The rest of the pattern is just the text you would expect to mark production mode.
In order to avoid all the output grep
is producing you can send it to /dev/null
:
grep "^[^#]* in production " file.conf > /dev/null || script file.ext
If you want to print a message, if you are in production mode and the script is not run you could do
grep "^[^#]* in production " file.conf > /dev/null &&
echo "We are in production mode. The script was not run." ||
script file.ext
edited Mar 4 at 19:40
answered Mar 4 at 16:32
katoshkatosh
1619
1619
add a comment |
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.
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%2f504297%2falert-or-execute-script-only-if-config-file-shows-not-in-production-mode%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