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 to pass hash as password to ssh server
Sparring against two opponents test
no sense/need/point
Should I simplify my writing in a foreign country?
about academic proof-reading, what to do in this situation?
What do you call a painting on a wall?
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?
When did England stop being a Papal fief?
Looking for sci-fi book based on Hinduism/Buddhism
Execute command on shell command output
How can a hefty sand storm happen in a thin atmosphere like Martian?
Meaning of the (idiomatic?) expression "seghe mentali"
Is it normal for gliders not to have attitude indicators?
Where are the "shires" in the UK?
What's the 2-minute timer on mobile Deutsche Bahn tickets?
Has the United States ever had a non-Christian President?
Determine if a grid contains another grid
Clarification of algebra in moment generating functions
Would a "Permanence" spell in 5e be overpowered?
Is there a word for food that's gone 'bad', but is still edible?
Dihedral group D4 composition with custom labels
In Futurama, how many beings has Leela slept with?
Make me a minimum magic sum
Dangerous workplace travelling
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 %s 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
3 mins ago
yes, thanks for the correction.
– mosvy
49 secs 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 %s 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
3 mins ago
yes, thanks for the correction.
– mosvy
49 secs 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 %s 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
3 mins ago
yes, thanks for the correction.
– mosvy
49 secs 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 %s 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 %s 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 3 mins ago
answered 35 mins ago
mosvymosvy
11.1k11340
11.1k11340
did you meanprintf '%sn' nl-terminated
in stead ofprintf %s nl-terminated
?
– iruvar
3 mins ago
yes, thanks for the correction.
– mosvy
49 secs ago
add a comment |
did you meanprintf '%sn' nl-terminated
in stead ofprintf %s nl-terminated
?
– iruvar
3 mins ago
yes, thanks for the correction.
– mosvy
49 secs ago
did you mean
printf '%sn' nl-terminated
in stead of printf %s nl-terminated
?– iruvar
3 mins ago
did you mean
printf '%sn' nl-terminated
in stead of printf %s nl-terminated
?– iruvar
3 mins ago
yes, thanks for the correction.
– mosvy
49 secs ago
yes, thanks for the correction.
– mosvy
49 secs 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