Questions tagged [pipe]

A Unix pipe connects file descriptors of two processes. A pipe is created with the POSIX pipe() function declared in <unistd.h>. Shells provide pipe creation between processes using "|".

Filter by
Sorted by
Tagged with
0
votes
2answers
30 views

xargs and zcat: silence errors

Suppose I have: ** EDIT TO HAVE CLOSER CORRESPONDENCE TO ACTUAL USAGE ** find ... -regex ... | head -n 1 | xargs -I {} zcat {} | head -n 1 # next, I do some other things now, everything works ...
0
votes
1answer
22 views

Command to create/connect to an I/O stream?

So I'm trying to connect to a (Lua) debugger embedded in a program by redirecting the I/O. Currently I create a pair of FIFOs for the read and write streams and connect to them using cat /tmp/...
0
votes
1answer
25 views

Pause execution of a list of commands

I have a file that has a list of bash commands like the following: echo 'foobar' echo 'helloworld' echo 'ok' And I can execute these commands by simply piping them to /bin/bash like so: cat ...
1
vote
0answers
33 views

Looking at the kernel logs to see if there is something wrong with my machine

My ubuntu machine slowed down, I was following these instructions: https://askubuntu.com/questions/21632/slow-response-and-system-lag the slowness I see is pretty uniform, and there's definitely a ...
0
votes
1answer
56 views

What happens when piping the `yes` to another command?

If the yes command echos "y" continuously until killed, then it will never get done right? If it will never get done then how does it pipe it's output to the next command??
-1
votes
1answer
40 views

Is there an attitude to avoid piping downloaded data sent to stdout?

Please consider the following command: wget FILE -O - | tar -xzv -C DESTINATION I understood from programmer who reviewed a Bash code I created that it is better to separate tar from wget to prevent ...
0
votes
0answers
43 views

Variable losing value [duplicate]

Anyone have suggestions? Thanks in advance. #!/usr/bin/env bash VAR=$( ssh -q -T -o ConnectTimeout=10 server01 " df -Ph" ; EXITSTATUS="$?" | sed -r '/^\s*$/d' | grep -v "test" | wc -l ) echo $...
1
vote
2answers
50 views

bash: filter text stream by command result

Is there a standard tool that can filter text stream based on command execution result? Consider grep for example. It can filter text stream based on regex. But the more general problem is extending ...
0
votes
0answers
28 views

Remove newline character after pipe

I want to do Base64 encode with a command echo -en "my_message" | openssl sha1 -hmac "secret_key" | base64 The output string of openssl is as expected, but the output of base64 is not as the output ...
0
votes
0answers
13 views

Piping Multiple stdouts to Python program?

I have a program that prints in stdout and I'd like multiple instances of it where each instance's stdout is piped to a sed and then the result(of three such sed) piped to a python program. I'm doing ...
3
votes
2answers
55 views

pipeline(“|”)-key alternative

I don't have a |-key. is there an alternative to it? say, can I execute an equivalent to dmesg | less if I can't type |? System # uname -a Linux devuan-droid4 5.4.0 #1 SMP PREEMPT Sun Jan 12 19:...
0
votes
1answer
25 views

How to add error handling for ansible shell module with pipes?

I have an Ansible shell module like below. - name: "Verifying file" shell: cat filename | grep something | tail -1 | awk '{print $4}' register: hname How to do error handling like if one pipe ...
0
votes
1answer
27 views

Command that only displays ip address and subnet mask using ifconfig

I need help with my Linux laboratories. Does anybody know a combination of command complies with this exercise? Look at the output of /sbin/ifconfig. Write a line that only displays IP address and ...
0
votes
2answers
38 views

Make cat interpret input as file (not string)

cat has two different behaviours depending on if its input is a string of file. I need to use cat to pipe a file to my PDF viewer (Zathura). The file name is based on a modified string with sed as ...
1
vote
1answer
71 views

Piping errors to my function causes command to be ignored after 1 failure

Context: I have a Bash Script that copies files function log () { read IN if [ "$IN" == "" ]; then : else echo "$datetime"$'\t'"$IN" | tee -a logfile fi } function ...
0
votes
2answers
64 views

How does pipe work in bash commands?

Does anything symbolic happen in chaining bash commands via a pipe or is it all compute-pass-compute-pass? For example in head t.txt -n 5 | tail -n 2, is head t.txt -n 5 getting computed and then ...
2
votes
1answer
58 views

How to get PIDs of shells in pipeline? [duplicate]

For example, I run sleep 1 | sleep 2 | sleep 3 & How do I get process ids of each part? I could examine output of jobs -l but its format may wary among shells and I am looking for a simpler way.
0
votes
1answer
31 views

What is this code actually doing?

While doing a CTF challenge on a platform, I needed a reverse shell but couldn't get one working so I looked at the processes and found one reverse shell code: rm /tmp/m;mkfifo /tmp/m;cat /tmp/m|/bin/...
1
vote
0answers
28 views

Variable not available outside function [duplicate]

I'm having difficulties understanding the following example I created. The variable glob_var gets changed inside the test() function, but the original value remains outside of the function: test() { ...
1
vote
3answers
110 views

Multiple commands and subshell execution after pipeline

Ok, I know that in Bash (by default, without 'lastpipe' bash option enabled) every variable assigned after a pipeline is, indeed, executed in a subshell and the variable itself dies after subshell ...
1
vote
1answer
32 views

Definition of list is confusing

In the GNU bash manual, a list is defined as A list1 is a sequence of one or more pipelines separated by one of the operators ‘;’, ‘&’, ‘&&’, or ‘||’, and optionally terminated by one ...
1
vote
2answers
67 views

How does exactly pipelining work with 2>&1?

Just started learning UNIX so the question might seem really newbie but would appreciate the answer, as I've been trying to work it out on my own for an hour already with google's help, with no ...
0
votes
1answer
42 views

How to pipe:/// through a .sh or Python script, or use some sort of setting files with FFMPEG

First post, so be kind please :) So a quick bit of history. I am using tvheadend, and the inbuilt transcoder murders my CPU, and provides average quality output (it's powered by ffmpeg), if I pipe ...
0
votes
0answers
21 views

Pipeline combining echo and cat, result is unexpected [duplicate]

echo "file.txt" | cat According to the man of bash pipelines: the output of the first command, which in this case is echo "file.txt", is used as the input of the second command, which in this case is,...
0
votes
1answer
28 views

Cache stdout data and forward it stdout

I am running a command line tool in Linux that emits data every 10ms. I'll forward this to another application to visualize the data. I would like to cache for example 10 incoming messages from stdin ...
0
votes
0answers
41 views

Using tr to convert newline to null stops stream output

I'm using the saw and jq plus some filtering to get pretty-printed JSON log streams, but what I have below has no output. It just hangs. saw watch /aws/ecs/container-log \ | sed -e 's/^\[.*\] \(.*\)(....
0
votes
0answers
27 views

Continuously read self overwritten outputs and parsing the lines

Sometimes a program outputs content that is self overwritten by default. For example, the output of dd if=(something) of=(something) status=progress has the following output model: 56670413312 bytes (...
0
votes
3answers
62 views

Piping data to a script or function, determining whether the output is coming to stdout or stderr?

I'm trying to create a general-purpose function or script that I can pipe data into, and prepend the output showing which fd the data "arrived" on (stdout or stderr). My Bash skills are intermediate ...
0
votes
2answers
44 views

Find all files and list all attributes in terminal

I can list all test.txt files on RHEL terminal using sudo find / -iname 'list.txt' If there is a file /media/my/list.txt I can run sudo ls -la /media/my/list.txt to get the attributes. How can I ...
1
vote
1answer
40 views

Is it possible to write an alias or function in Bash to filter out the errors (stderr)?

I sometimes would do grep -ri foo . but in some node_modules, it could have some links to places that don't exist. So I can do a grep -ri foo . 2>&- or grep -ri foo . 2> /dev/null but ...
0
votes
1answer
35 views

cut -d not working?

I'm trying to extract all the lines from a file that end with /42 and then remove said /42 with the command cut but for some reason its not working. Here is the command grep "42$" questionnaires.txt &...
0
votes
1answer
72 views

Trying to run .sh script from curl

I am having trouble running a shell script. So for context, I am using bash <(curl -s -L https://test.com/detect.sh) --argument1=true When I run this command in my Ubuntu environment, it works ...
0
votes
1answer
50 views

How do I account for a variable number of extra arguments in a bash script?

It is set up so that $1 is the flag for what the program is going to do, $2 can be a username or anything else. This works great except for one thing: I have to be able to add a comment to a user, and ...
1
vote
2answers
35 views

Underlying failure after a SIGPIPE

I am getting an error code 141 when running a bash script on a CI server that I cannot reproduce locally. After some searching, it sounds that error 141 indicates a PIPEFAIL, and I have a set -o ...
0
votes
2answers
43 views

Filtering ping output through multiple pipes fails

Trying to capture only the packets return time from ping output, I issued $ ping 192.168.0.1 | grep -o '[^ =]* ms' and it worked, displaying each packet time when it arrived. Since I also wanted to ...
0
votes
0answers
13 views

Pipe email through translation program and save results to mailbox

My mail service uses exim to filter mail and I have some experience putting in various conditions in my .forward file. However, I have a more complex problem that I don't know how to solve. ...
0
votes
0answers
13 views

Streaming to FIFO-Q: how to copy into two streams, and operate on the new streams?

This question is about pipes, and I have created a small problem to illustrate my issue. Suppose I have a file: // foo.csv a,b,c d,e,f In script bar.sh, I do the following: A=`mktmp -u` B=`mktmp -...
0
votes
2answers
77 views

Can I cp to stdout/pipe?

Ok, it might sound weird but bear with me. I want to use cp to copy content of my block device, and I want to pipe it to gzip to compress it on the fly. Can I do this with cp? I know I can use dd, but ...
1
vote
1answer
103 views

Why is `BrokenPipeError` dependent on the size of the piped stream?

The following script raises BrokenPipeError: [Errno 32] Broken pipe, when piped to a command like head (unless the number of lines to head exceeds the number of lines printed by the Python script). ...
0
votes
2answers
26 views

How do I pipe the results of a “find” or “ls” to a file AFTER it has completed its stdout?

So for some reason when I do something like find $PWD -type f > listoffiles.txt To create a list of files in current directory and save it to a list, The file "listoffiles.txt" itself is somehow ...
0
votes
1answer
50 views

Named pipe buffer after process end

I am creating named pipes in Ubuntu 18 and 16 environments in C language using gcc as compiler (mkfifo() and open()). One of the things I noticed that the named pipes remain in the filesystem after ...
0
votes
0answers
18 views

modify binary output before returning to the prompt mode

I have a binary which prints the question and then waits for a user answer. I have no access to the source code of this binary, but I want to modify the screen output. Example: > ./commandx Day ...
0
votes
0answers
28 views

Show ports in hexadecimal for netstat or ss command

I am trying to format the output of netstat or ss command in bash terminal. I need to convert the port numbers to hexadecimal. Currently they are shown in decimal by default. Is there any option in ...
0
votes
1answer
58 views

Interacting programs stdin and stdout (create a robot program to play a game)

The setup: I have an executable file, that I "cannot edit", since I don't have the source code. When I execute the program it reveals a game, where it hands me some numbers via stdout, for me to ...
2
votes
1answer
134 views

problem understanding system(“/bin/sh”)

I'm having problems understanding why this program #include <stdio.h> #include <stdlib.h> int main() { int iRetval = 0; unsigned int uiNum; printf("Enter number: "); ...
0
votes
0answers
34 views

pipe script to bash and also use read

If I do this: $ { > sleep 1 > read -p "Press Enter to continue" > } I get the prompt after a second, as expected. Now, if I do this: $ echo 'sleep 1; read -p "Press Enter to continue";' | ...
0
votes
0answers
31 views

sudo from standard in on interactive command

I'm trying to run the command cat ./password | sudo -Skp '' yum install git and it goes through the motion and finally gets to the last line where it returns Is this ok [y/N]: Operation aborted. ...
0
votes
1answer
31 views

Best way to set a conditional output filter (head or output “as is”) [duplicate]

For testing purpose, I want to activate or not a filtering with the command head. For example, the command below could outputs a lot of lines #!/bin/bash produce_a_lot_of_lines I want to set on ...
0
votes
0answers
25 views

Mailgun script working and | tee not logging

I've got a bash script running from Windows task scheduler: Looks like this: C:\Windows\System32\bash.exe -c "sudo /root/borgbackup.sh 2>&1 | tee -a /tmp/borg.log | sudo /root/mailgun 2>&...
19
votes
2answers
2k views

Piping commands with very large output

I want to tar a directory and write the result to stdout, then pipe it to a compression program, like this: tar -cvf - /tmp/source-dir | lzip -o /media/my-usb/result.lz - I have been using pipe all ...

1
2 3 4 5
29