Execute command on shell command outputShell script to execute a command with iterationexecute shell script optionsShell script to execute psql commandBash: move files of specific patternExecute command on multiple severs in parallel using shell scripttimeout causes while read loop to end when `cat` is timed outShell script to ls and execute command on ls resultExecute command without terminal outputHow to write a function that reliably exits (with a specified status) the current process?Execute python file from shell script based on the cat/awk output
How did the Apollo guidance computer handle parity bit errors?
Does running exec do anything?
Is there a word for food that's gone 'bad', but is still edible?
How can a hefty sand storm happen in a thin atmosphere like Martian?
Why didn't this character get a funeral at the end of Avengers: Endgame?
It isn’t that you must stop now
Meaning of the (idiomatic?) expression "seghe mentali"
How to preserve a rare version of a book?
Why did WWI include Japan?
Krull dimension of the ring of global sections
Dihedral group D4 composition with custom labels
Will a God Eternal enchanted with Deep Freeze shuffle back into the deck if it dies?
The origin of list data structure
Clarification of algebra in moment generating functions
What happens if I accidentally leave an app running and click "Install Now" in Software Updater?
Where are the "shires" in the UK?
Should homeowners insurance cover the cost of the home?
What do you call a painting on a wall?
How can Internet speed be 10 times slower without a router than when using the same connection with a router?
In Futurama, how many beings has Leela slept with?
What is a common way to tell if an academic is "above average," or outstanding in their field? Is their h-index (Hirsh index) one of them?
Game artist computer workstation set-up – is this overkill?
Make me a minimum magic sum
How to calculate rate of axial precession?
Execute command on shell command output
Shell script to execute a command with iterationexecute shell script optionsShell script to execute psql commandBash: move files of specific patternExecute command on multiple severs in parallel using shell scripttimeout causes while read loop to end when `cat` is timed outShell script to ls and execute command on ls resultExecute command without terminal outputHow to write a function that reliably exits (with a specified status) the current process?Execute python file from shell script based on the cat/awk output
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a command that runs forever and periodically output stuff until it gets killed by something else (similar to tail -f
), and I want to make it so that whenever there's new output another command gets executed.
Caveats:
- I can't use Bash
- That command obviously isn't
tail
, it just behaves in a similar manner - That command's output doesn't always come in lines, and I do not intend to execute that other command for each line of the output
- Polling is not an acceptable solution
shell-script shell
add a comment |
I have a command that runs forever and periodically output stuff until it gets killed by something else (similar to tail -f
), and I want to make it so that whenever there's new output another command gets executed.
Caveats:
- I can't use Bash
- That command obviously isn't
tail
, it just behaves in a similar manner - That command's output doesn't always come in lines, and I do not intend to execute that other command for each line of the output
- Polling is not an acceptable solution
shell-script shell
add a comment |
I have a command that runs forever and periodically output stuff until it gets killed by something else (similar to tail -f
), and I want to make it so that whenever there's new output another command gets executed.
Caveats:
- I can't use Bash
- That command obviously isn't
tail
, it just behaves in a similar manner - That command's output doesn't always come in lines, and I do not intend to execute that other command for each line of the output
- Polling is not an acceptable solution
shell-script shell
I have a command that runs forever and periodically output stuff until it gets killed by something else (similar to tail -f
), and I want to make it so that whenever there's new output another command gets executed.
Caveats:
- I can't use Bash
- That command obviously isn't
tail
, it just behaves in a similar manner - That command's output doesn't always come in lines, and I do not intend to execute that other command for each line of the output
- Polling is not an acceptable solution
shell-script shell
shell-script shell
asked 1 hour ago
Hwi417Hwi417
312
312
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Here is an example of using dd
to trigger a shell command whenever something is read from stdin, whether terminated by newline or not:
printf not-nl-terminated
sleep 1
printf '%sn' nl-terminated
sleep 1
printf 'other1junk'
|
while : ; do
input=$(dd bs=1G count=1 2>/dev/null)
[ "$input" ] || break
printf 'input of size %dn' "$#input"
done
will give
input of size 17
input of size 13
input of size 10
This snippet from the standard spec may help understand dd
's behavior when bs=
is used explicily:
If the
bs=
expr operand is
specified and no conversions other thansync
,noerror
, ornotrunc
are requested, the data returned from each input block shall be
written as a separate output block; if the read returns less than a
full block and thesync
conversion is not specified, the resulting
output block shall be the same size as the input block. If thebs=
expr operand is not specified, or a conversion other thansync
,
noerror
, ornotrunc
is requested, the input shall be processed and
collected into full-sized output blocks until the end of the input
is reached.
Note:
If the input data may contain NUL bytes, you may want something like
input=$(dd bs=1G count=1 2>/dev/null | tr '' _)
or parse the status lines that dd
writes to stderr.
did you meanprintf '%sn' nl-terminated
in stead ofprintf %s nl-terminated
?
– iruvar
4 mins ago
yes, thanks for the correction.
– mosvy
2 mins ago
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%2f517168%2fexecute-command-on-shell-command-output%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
Here is an example of using dd
to trigger a shell command whenever something is read from stdin, whether terminated by newline or not:
printf not-nl-terminated
sleep 1
printf '%sn' nl-terminated
sleep 1
printf 'other1junk'
|
while : ; do
input=$(dd bs=1G count=1 2>/dev/null)
[ "$input" ] || break
printf 'input of size %dn' "$#input"
done
will give
input of size 17
input of size 13
input of size 10
This snippet from the standard spec may help understand dd
's behavior when bs=
is used explicily:
If the
bs=
expr operand is
specified and no conversions other thansync
,noerror
, ornotrunc
are requested, the data returned from each input block shall be
written as a separate output block; if the read returns less than a
full block and thesync
conversion is not specified, the resulting
output block shall be the same size as the input block. If thebs=
expr operand is not specified, or a conversion other thansync
,
noerror
, ornotrunc
is requested, the input shall be processed and
collected into full-sized output blocks until the end of the input
is reached.
Note:
If the input data may contain NUL bytes, you may want something like
input=$(dd bs=1G count=1 2>/dev/null | tr '' _)
or parse the status lines that dd
writes to stderr.
did you meanprintf '%sn' nl-terminated
in stead ofprintf %s nl-terminated
?
– iruvar
4 mins ago
yes, thanks for the correction.
– mosvy
2 mins ago
add a comment |
Here is an example of using dd
to trigger a shell command whenever something is read from stdin, whether terminated by newline or not:
printf not-nl-terminated
sleep 1
printf '%sn' nl-terminated
sleep 1
printf 'other1junk'
|
while : ; do
input=$(dd bs=1G count=1 2>/dev/null)
[ "$input" ] || break
printf 'input of size %dn' "$#input"
done
will give
input of size 17
input of size 13
input of size 10
This snippet from the standard spec may help understand dd
's behavior when bs=
is used explicily:
If the
bs=
expr operand is
specified and no conversions other thansync
,noerror
, ornotrunc
are requested, the data returned from each input block shall be
written as a separate output block; if the read returns less than a
full block and thesync
conversion is not specified, the resulting
output block shall be the same size as the input block. If thebs=
expr operand is not specified, or a conversion other thansync
,
noerror
, ornotrunc
is requested, the input shall be processed and
collected into full-sized output blocks until the end of the input
is reached.
Note:
If the input data may contain NUL bytes, you may want something like
input=$(dd bs=1G count=1 2>/dev/null | tr '' _)
or parse the status lines that dd
writes to stderr.
did you meanprintf '%sn' nl-terminated
in stead ofprintf %s nl-terminated
?
– iruvar
4 mins ago
yes, thanks for the correction.
– mosvy
2 mins ago
add a comment |
Here is an example of using dd
to trigger a shell command whenever something is read from stdin, whether terminated by newline or not:
printf not-nl-terminated
sleep 1
printf '%sn' nl-terminated
sleep 1
printf 'other1junk'
|
while : ; do
input=$(dd bs=1G count=1 2>/dev/null)
[ "$input" ] || break
printf 'input of size %dn' "$#input"
done
will give
input of size 17
input of size 13
input of size 10
This snippet from the standard spec may help understand dd
's behavior when bs=
is used explicily:
If the
bs=
expr operand is
specified and no conversions other thansync
,noerror
, ornotrunc
are requested, the data returned from each input block shall be
written as a separate output block; if the read returns less than a
full block and thesync
conversion is not specified, the resulting
output block shall be the same size as the input block. If thebs=
expr operand is not specified, or a conversion other thansync
,
noerror
, ornotrunc
is requested, the input shall be processed and
collected into full-sized output blocks until the end of the input
is reached.
Note:
If the input data may contain NUL bytes, you may want something like
input=$(dd bs=1G count=1 2>/dev/null | tr '' _)
or parse the status lines that dd
writes to stderr.
Here is an example of using dd
to trigger a shell command whenever something is read from stdin, whether terminated by newline or not:
printf not-nl-terminated
sleep 1
printf '%sn' nl-terminated
sleep 1
printf 'other1junk'
|
while : ; do
input=$(dd bs=1G count=1 2>/dev/null)
[ "$input" ] || break
printf 'input of size %dn' "$#input"
done
will give
input of size 17
input of size 13
input of size 10
This snippet from the standard spec may help understand dd
's behavior when bs=
is used explicily:
If the
bs=
expr operand is
specified and no conversions other thansync
,noerror
, ornotrunc
are requested, the data returned from each input block shall be
written as a separate output block; if the read returns less than a
full block and thesync
conversion is not specified, the resulting
output block shall be the same size as the input block. If thebs=
expr operand is not specified, or a conversion other thansync
,
noerror
, ornotrunc
is requested, the input shall be processed and
collected into full-sized output blocks until the end of the input
is reached.
Note:
If the input data may contain NUL bytes, you may want something like
input=$(dd bs=1G count=1 2>/dev/null | tr '' _)
or parse the status lines that dd
writes to stderr.
edited 4 mins ago
answered 36 mins ago
mosvymosvy
11.1k11340
11.1k11340
did you meanprintf '%sn' nl-terminated
in stead ofprintf %s nl-terminated
?
– iruvar
4 mins ago
yes, thanks for the correction.
– mosvy
2 mins ago
add a comment |
did you meanprintf '%sn' nl-terminated
in stead ofprintf %s nl-terminated
?
– iruvar
4 mins ago
yes, thanks for the correction.
– mosvy
2 mins ago
did you mean
printf '%sn' nl-terminated
in stead of printf %s nl-terminated
?– iruvar
4 mins ago
did you mean
printf '%sn' nl-terminated
in stead of printf %s nl-terminated
?– iruvar
4 mins ago
yes, thanks for the correction.
– mosvy
2 mins ago
yes, thanks for the correction.
– mosvy
2 mins ago
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%2f517168%2fexecute-command-on-shell-command-output%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