Tag Info

New answers tagged

1

I found solution: #!/bin/bash mkfifo /etc/z.conf ( while (true) do ssh x@y cat /etc/z.conf > /etc/z.conf done ) &


1

wget -qO - |gzip -c > file_name.gz -c for stdout . that's '>' used. the file get from wget serialize to file_name.gz using standard output library. -qO to send output file


3

You will need to store the output in a variable to accomplish this. Here is an example: if output=$(cmda); then printf '%s' "$output" | cmdb fi


3

In the first line, xargs still waits for the second argument or an end of the input. After pressing Ctrl-D xargs continues with the rest and you will see the 5th x as single argument. This example may explain the behavior: (echo "x x x x x"; sleep 5; echo "x") | xargs -n2 Output: x x x x x x # after 5 seconds After the 6th x in the second echo ...


13

Do you really want to tar the file or are you looking for downloading a file into a compressed form. Tarring a file is just bundling (uncompressed) files into an (uncompressed) archive. If you want to download a file into a compressed file you can use: wget -qO - <url>|gzip -c - > file.gz


4

This is not going to work the way you want it to. A file (obviously with a filename) needs to be stored in the tar. That bit (the filename) is obviously missing if you just pipe the contents of the download to tar. I don't see any way to tell tar that it should pack stdin and specify a filename for that. That said, I really do not say a way to achieve that ...


8

You can't deal with input streams in that way. It is designed to deal with files. If you had managed to create an archive as you describe, what would it look like? How would you untar it? There would be no filename to create, just data. I think your best bet is to get the file and tar it in two separate commands. If you don't want the file to remain on ...


2

bash has both an interactive mode and a batch mode. It enters the corresponding mode depending if stdin is a terminal or not. bash # interactive cat|bash # non-interactive: stdin is a pipe not a terminal cat|bash -i # explicitly request interactive mode In interactive mode bash will print a prompt (configurable by the PS1 variable) and also set ...


5

You can try things out with a script such as #!/bin/sh for fd in 0 1 2; do if [ -t $fd ]; then echo $fd is a TTY; fi done Running this I see that: if the script is run on its own, all three FDs are TTYs if the script is run at the start of a pipeline, stdin and stderr are TTYs if the script is run in the middle of a pipeline, stderr is a TTY if the ...


4

LC_ALL=C </dev/urandom \ tr '\0-\377' '[0*128][1*]' | dd ibs=50 cbs=10 conv=unblock count=1 That will convert all input ascii bytes (which will be all bytes because LC_ALL=C is specified) into one of either 0 or 1 on an even distribution. The first 128 bytes between \0 and \177 are converted to zeroes and the \200-\377 to ones - and so you get to use ...


1

then I tried to fill a file with this stream (and end the process of filling by ctrl+c) cat /dev/urandom | tr -dc 01 > foo when I count the numbers of lines of the so created foo file I get 0 lines. cat foo | wc -l 0 Both cat and tr buffer their output. When you press Ctrl+C, any data that's still in either command's buffer is lost. You ...


7

How about fold? It's part of coreutils... $ tr -dc 01 < /dev/urandom | fold -w 30 | head -n 5 001010000111110001100101101101 000101110011011100100101111000 111010101011100101010110111001 111011000000000101111110110100 110011010111001110011010100011 Or if that's not available, some flavour of awk: $ tr -dc 01 < /dev/urandom | awk \$0=RT RS=.\{,30} | ...


1

To add a newline during the generation process do: { process-without-terminating-newline ; echo ;} > outfile To add it to an existing file do: echo >> outfile


-1

I hope someone can help explain the following to me. I have a script that runs fine on Mac OSX, but does not on Ubuntu. Below is the script, then will follow the debug output from OSX then the debug output from Ubuntu, both created by using #!/bin/bash -x I can confirm that the contents of ./networks.txt is the same on both systems. If I run the first grep ...


2

pipeto Unfortunately, rlwrap's built-in filter pipeto does not filter output in the way you desire. I find the documentation rather misleading, but what it does is if you run rlwrap -z pipeto some-shell, then, within the interaction: if you type commands without any pipe sign (|), those are passed verbatim to some-shell and then the output of that is ...


1

smbclient -E -U $USERNAME //server/sharename $PASSWORD -c 'get \\dir\\filename.gz /dev/fd/1' 2>/dev/null | zcat | yourcommand The -E instructs smbclient to send all messages to standard error instead of standard out where those messages will mess up the output we actually want. I'm not interested in those messages so those are discarded by the ...


1

# put commands in an array, e.g.: cat /etc/passwd | grep 1555 | grep sh cmd=("cat /etc/passwd" "grep 1555" "grep sh") # execute commands eval "${cmd[0]}" | eval "${cmd[1]}" | eval "${cmd[2]}" # save PIPESTATUS save=("${PIPESTATUS[@]}") # print returncode and failed command for ((i=0;i<${#save[@]};i++)); do [[ ${save[$i]} -ne 0 ]] && echo ...


1

The following script I managed to put together seems to do it: #!/usr/bin/env ruby # -*- coding: utf-8 -*- require 'pty' PTY.spawn(*ARGV) do |r,w,pid| begin while $_ = r.gets STDOUT.print $_ end rescue Errno::EIO end end It runs its CLI arguments in a pseudoterminal and forwards the output to STDOUT. Usage example: ./script.rb ls ...


2

find | less When I hit shift+g (go to the end of file in less) HDD starts immediately to work and data starts outputting. Does this mean that when less command has enough data to display it will somehow tell find to not produce further data? No. Pipes work on read()s and write()s. less tells find nothing - but the system kernel which owns that pipe will ...


2

I'm surprised no one has mentioned the pee command from moreutils (https://joeyh.name/code/moreutils).


0

For eg: n=$(echo $(( (RANDOM%6) +1)). I have to grep this variable in /etc/passwd. So you're trying to print all lines of /etc/passwd that contain a random number from one to six? Wouldn't that just be (assuming bash or zsh or ksh for $RANDOM, which the base POSIX shell does not support): grep $((RANDOM%6+1)) /etc/passwd If you need that random ...


1

I notice your separating two commands that run in sequence and not sharing Io with a pipe rather than a semicolon. Try n=$(echo $(( (RANDOM%6) +1)) ; grep "$n" /etc/passwd


0

You could modify your script so that it adds backup$(date) instead of the generic "backuplocation" (and first create a folder called backuplocation only once) then: tar -czf backuplocation/backup-$(date).tar.gz backup$(date) mv backup-$(date).tar.gz backuplocation/ rm -rf backup$(date)


4

At least in bash you can skip mkfifo using process substitution: command -option1 -option2 argument | tee >(cmd1) >(cmd2) >(cmd3) or to adopt Arcege's example tee >(wc -l) >(wc -w) >(wc -c) < /etc/passwd >/dev/null


14

If I understand correctly, you're looking for the equivalent of tee file1 file2 file3, but rather than write the same data to three files file1, file2 and file3, you want to pipe the same data into three commands cmd1, cmd2 and cmd3, i.e. … | ??? cmd1 cmd2 cmd3 should be equivalent to … | cmd1 & … | cmd2 & … | cmd3 & except that … would ...


24

You could use named pipes (http://linux.die.net/man/1/mkfifo) on the command line of tee and have the commands reading on the named pipes. mkfifo /tmp/data0 /tmp/data1 /tmp/data2 cmd0 < /tmp/data0 & cmd1 < /tmp/data1 & cmd2 < /tmp/data2 & command -option1 -option2 argument | tee /tmp/data0 /tmp/data1 /tmp/data2 When command finishes, ...


2

Will tail -100 | sed -n 1p only read one line? No, sed will read 100 lines. If your goal is to read the 100th line from the end of the file, do one of tail -100 | head -1 tail -100 | sed 1q


0

The tail commands have some intelligence implemented (so I've heard and also experienced); if you test tail on very large files you will see that it takes no time to get to the last portion of the file. In your case you will only pass $numberOfLines lines through the first pipe and 1 line through the second pipe.


0

It is indeed timing related. If you don't want to see your grep command there's two things you can do, depending on your usecase. If you only need to see the pids resort to: pgrep -l python If you need more detail: ps aux | grep python | grep -v grep


1

It is timing related. You almost always don't want the grep command itself to be part of the output, especially when you're filtering ps and plan on killing the results ;-) The usual idiom/trick to do that is: while true; do ps aux | grep [a]bc; echo done; sleep 1; done Which means grep will still find anything with abc, but the grep command itself ...


4

To answer your list of questions by number: Named pipes, a.k.a. fifos, are essentially equivalent to unnamed pipes generated by the shell. The big difference is that synchronization between the two ends is intuitive with the shell version, while named pipes as you seem to be using them require a bit of knowledge about what the shell is doing for you. Yes, ...


3

The error is because you are redirecting all output to $logfile so there is no output for yad to process. The tool you're looking for is tee: NAME tee - read from standard input and write to standard output and files SYNOPSIS tee [OPTION]... [FILE]... DESCRIPTION Copy standard input to each FILE, and also to standard output. So, you ...


2

This is similar to a couple of the other answers.  If you have the “moreutils” package, you should have the sponge command.  Try commandA | sponge | { read -r x; { printf "%s\n" "$x"; cat; } | commandB; } The sponge command is basically a pass-through filter (like cat) except that it does not start writing the output until it has read the entire input.  ...


0

You can solve the requirement with a little script. This particular variant avoids the temporary file and potential memory hog at the expense of additional processes. #!/bin/bash # IFS= read LINE if test -n "$LINE" then test -t 2 && echo "Starting $*" >&2 ( echo "$LINE" cat ) | "$@" else exit 0 fi If you ...


1

Commands in pipe line are started concurrently, you need to store commandA output somewhere to use later. You can avoid temp file by using variable: output=$(command A; echo A) printf '%s' "${output%%A}" | commandB


1

I don't know of any standard UNIX utility that can address this issue. One option would be use awk to accumulate commandA output and flush it to commandB at one shot, like so commandA | awk '{x = x ORS $0}; END{printf "%s", x | "commandB"}' Beware that this could be memory intensive since awk is building up a string from its input.


2

There is one case where it can be useful to not use spaces. If you're not using a US-American layout, you may be forced to use some combinations like AltShiftL to input a pipe. While this is not a problem per se, one consequence is that sometimes you also input non printing characters before or after that character. For example, on a french Macbook Pro ...


17

bash defines several metacharacters. From man bash: metacharacter A character that, when unquoted, separates words. One of the following: | & ; ( ) < > space tab Because metacharacters separate words, it does not matter whether they are surrounded by spaces. The pipe symbol, |, is a metacharacter and hence, as you ...


3

Pipes let you use the output of a program as the input of another one ... As far as spaces , its just matter of readability / personnel preference like @jasonwryan mentioned. One space-bar before and after "|" is the norm .... You can also use it with column -t , to not just make your one liner neat , but also your output. lnydex99uhc:depot_r user$ ...


1

The only significance of spaces in this case is aesthetics. Or in other words useful to make the commands more readable to a human.


1

2>&1 duplicates standard output as standard error. </dev/null redirects standard input to the null character special device, eof is encountered immediately when reading. |head -n1 pipes standard output to the command, thus the first line is printed, and lines after the first are discarded.


0

I found a solution to my question on another stack exchange site: enter link description here Basically, I ssh from my mac into my Pi and send my arecord and lame command to the Pi. I then pipe stdout to mplayer (or anything really) via the command line. ssh pi@ip_of_pi "arecord --buffer-time=5000000 -D plughw:1,0 -f cd -t raw | lame -r - " | mplayer -


8

The problem is that you'll be checking the exit status of pv. With POSIX sh syntax, you could do: cd /app && ((make 3>&- && exec sudo nginx -g 'daemon off;' >&3 3>&-) | pv -qL 100) 3>&1 Or with ksh/bash/zsh: (set -o pipefail cd /app && make | pv -qL 100 && sudo nginx -g 'daemon off;') Or with ...



Top 50 recent answers are included