Tag Info

New answers tagged

0

I'm sure it ought to be possible. I can only suggest a hack where you use extra ssh connections to each carry another pair of file descriptors. E.g. the following proof of concept script does a first ssh to run a dummy command (sleep) to connect up local fds 5 and 6 to remote stdin and stdout, presuming these fds are the ones you want to add to the usual ...


3

You can do this using socket forwarding, which is available since openssh-6.7. This is some kind of pipe. This technique is described for example here: http://www.25thandclement.com/~william/projects/streamlocal.html You will gain two-direction route for your data. There is example with mysql: Proxy MySQL client connections on a remote server to your ...


2

If prog2 follows a common convention you could use - as the "file" to tell it to read from stdin and then the pipeline would be prog1 <inputfile> - min max | prog2 - <outputfile> min max which would tell prog1 to write to stdout as its output file, and prog2 would use stdin as its input file with the pipe connecting those two. This would not ...


3

The command you're trying is trying to treat cat as a file, shoving it's contents into mysql's STDIN. Instead, you need the results of the cat command shoved into STDIN, which can be done a couple different ways. The way I would do it would be to pipe the output of cat into mysql: $ cat schema/db1/*.sql | mysql -u root Equally validly, you can use: $ ...


3

Here's a summary of some of the drawbacks of: cat $file | cmd over < $file cmd First, a note: there are (intentionally for the purpose of the discussion) missing double quotes around $file above. In the case of cat, that's always a problem except for zsh; in the case of the redirection, that's only a problem for bash or for some other shells only ...


-2

The statement contains two uses of cat. cat file | wc | cat > file2 Clearly the 2nd cat is of no value, as cat file | wc > file2 has the same meaning in all shells I have ever used. However < file wc > file2 does not work in all shells. Not everyone is using a modem shell on a modem version of unix. (It can be off benefit to ...


22

cat file | wc | cat > file2 would usually be two useless uses of cat as that's functionally equivalent to: < file wc > file2 However, there may be a case for: cat file | wc -c over < file wc -c That is to disable the optimisation that many wc implementations do for regular files. For regular files, the number of bytes in the file ...


7

Let's suppose prog forks a new subprocess and exits, and the new subprocess writes something to its standard output and then exits. Then the command prog won't wait for the subprocess to exit, and it will display the shell prompt early. But the command prog | cat will wait for an EOF on the stdin of cat, which effectively waits for the subprocess to ...


14

While I don't disagree with the argument for saying it is a 'useless use of cat', there can be reasons for it: In many languages (including English) words and sentences are read from left to right, so showing the flow of data in the same way can appear more natural to the reader. A reason for the second cat could be to mask the return code. Such as: $ wc ...


36

Both of those examples are useless uses of cat. Both are equivalent to wc < file1 > file2. There is no reason to use cat in this example, unless you are using cat file as a temporary stand-in for something that dynamically generates output.


0

An alternative privilege-less approach is to use the fakeroot program to pretend that you are allowed to change ownership. While other tar attributes are lost, it does keep the mode, mtime and uid/gid. These commands create a temporary directory, extract a subset of the files and finally creates a new archive: mkdir tmp <some.tar.gz \ fakeroot -- sh -c ...


7

bsdtar (based on libarchive) can filter tar (and some other archives) from stdin to stdout. It can for example pass through only filenames matching a pattern, and can do s/old/new/ renaming. It's already packaged for most distros, for example as bsdtar in Ubuntu. sudo apt-get install bsdtar # or aptitude, if you have it. # example from the man page: ...


3

The easiest way would be to copy the whole archive; I presume you don't want to do that because it's too large. The usual command line tools (tar, pax) don't support copying members of an archive to another archive. If you didn't need to preserve ownership, I'd suggest using FUSE filesystems. You can use archivemount to mount an archive as a filesystem; do ...


-1

From what I know, the tar command cannot use the tar format both as input and output. You will have to extract your files locally somehow, and use tar again to create a tarfile on-the-fly, with something like this (the - means standart input/output is used instead of a file) : tar cf - subdir/ | ssh remote@system 'cd extractdir && tar xvf -' ...


0

because you are taking input of less from somefile. it works like this 1 -> execute ls , as you have used pipe , it will pipe stdout to stdin of next command : this is what you are telling 2 -> it will look second command.. it is less < somefile as soon as it sees '<' redirection it will change stdin again to the file... Hence your previous change ...


5

You cannot refer variable updates made in the child process (pipe connected while block). Instead, feed data using input redirection like this: #!/bin/bash data_file="$1" down=() counter=0 while read line; do isEven=$(( $counter % 2 )) if [ $isEven -eq 0 ]; then down+=("$line") fi (( counter ++ )) done < $data_file echo ...


0

This depends on the shell you are using. Try to call: yourshell -c 'echo bla | read VAR; echo $VAR' and check what is printed. Another check is to run: yourshell -c 'ps -f| more' with different shells and look at PID and PPID. Every shell uses its own different method.


13

wc will tell you what file it's working on if it's able. With the first one with the pipe it's reading from stdin, not a file, so does not report a filename. The second one, however, you're using process substitution which presents the output of the command as a file, which wc reports. It reports on the file descriptor it was given from which to read.


2

SSH keys First of all, the best solution for you would be to create new ssh keypair and use this key to login to all your servers (or some, based on preferences). If you don't know how, you can find it many times here on stackexchange, but shortcut: ssh-keygen; ssh-copy-id your-host Basically you should set passphrase for your key, so you will log in ...


0

There is also dpipe, the "bi-directional pipe", included in vde2 package, and included in current distro package management systems. http://manpages.ubuntu.com/manpages/trusty/man1/dpipe.1.html dpipe processA = processB


0

Similar to what Tim and Eric say, when you use > to redirect the STDOUT to a file, nothing is left over for the | to pipe into sort. Instead, you can use tee which does 2 things at the same time: Directs STDIN to a file Directs STDIN to STDOUT This has the result of both saving the STDIN (your ls command) to a file, and continuing it out to STDOUT to ...


2

is easy and there are many ways to do, for example v=$(echo $x1+$x2 | bc) v=`echo $x1+$x2 | bc` Note that bc is integer arithmetics only and that you need bc -l for a proper math library. Note that you can skip the echoing with the 'here' redirection <<< for strings: v=$( bc <<< $x1+$x2 )


2

ls > a.txt | sort > b.txt You are executing ls. Then you are redirecting only the STDOUT of the ls command into a.txt. Then you are trying to also PIPE STDOUT to the STDIN of the sort command. Because STDOUT is being redirected into the file a.txt, there is nothing in the STDIN of the sort command to be sorted into b.txt, which is why the file is ...


12

The | will take the output of the command on the left and give it to the input of the command on the right. The > operator will take the output of the command and put it into a file. That means, in your example, by the time it gets to the | there is no output left; it's all gone into a.txt. So the sort on the right operates on an empty string and saves ...


0

A small part of your problem may lie in the fact that you are doing an open inside your while (1) … read loop (without closing the resulting file descriptor in the loop).  Your code can be expected to accumulate hundreds of file descriptors for the FIFO.  Typically, after you hit a thousand, the open will start failing because of too many open files ...


0

You're only sending sizeof(float) bytes, which is only a substring of depthstring, whose actual size is strlen(depthstring)+1, not sizeof(float). One thing you could do is eliminate the conversion to and from a string. Since both processes reading a named FIFO are on the same machine (no, FIFOs don't work over NFS), you can assume that a float is ...


3

ddrescue is a tool that will try to help you get data from a disk that is dying, where it may be necessary to reread the same parts of a file several times until no error occurs anymore. To be able to do that, it needs to seek the input file, which is impossible on a pipe. It's also pretty pointless to try to use ddrescue unless your disk is, in fact, ...


0

I know this is an old question and already had lot of answers, but if you wish to avoid the buffer problem, just try something like: stdbuf -oL tail -f /var/log/messages | tee -a /home/your_user_here/logs.txt This will output in real time the logs and also save them into the logs.txt file and the buffer will no longer affect the tail -f command.


0

This is what I came finally up with, thanks to the neat Perl command contributed by JJoao: # kill everything on termination trap "kill 0" SIGINT SIGTERM # Make sure the remote processes are killed on exit, see http://unix.stackexchange.com/questions/103699/kill-process-spawned-by-ssh-when-ssh-dies shopt -s huponexit ( while [ 1 -eq 1 ]; do ssh -t -t ...


2

Some experiments: $ yes | sleep 10m & [1] 32395 32396 $ pstree -pa $(ps -o ppid= -p $(pgrep yes)) zsh,29630 ├─pstree,32402 -pa 29630 ├─sleep,32396 10m └─yes,32395 As can be seen, the parent of both processes is the shell. With a longer pipeline: $ sleep 10m | sleep 10m | sleep 10m | sleep 10m & [1] 32320 32321 32322 32323 $ pstree -pa $(ps ...


4

It's the shell; as you will see via the ps command, in that case the PPID of less will be the PID of the shell. The processes ls and less haven't much in common; it's just that the stdout of the former is piped in the stdin of the latter.


0

Recently I have learned about the command name ifne which is part of the moreutils package. Where you can use it to solve this specific problem. ifne - Run command if the standard input is not empty example from the man page, EXAMPLE find . -name core | ifne mail -s "Core files found" root


0

As I understand it, piped processes all start more-or-less at the same time. Generally, the processes in a pipeline will read from stdin or write to stdout (or both), and completion of the I/O will dictate when the process ends. For processes that don't have any output (like touch) or any standard input (like cat when operating on a file), I would generally ...


2

Okay, considering that scr.txt file contains some text before executing command and scr6.txt doesn't exist yet: the command touch ~/scratches/scr6.txt | cat ~/scr.txt > ~/scratches/scr6.txt | cat /dev/null > ~/scr.txt Empty scr.txt file (cat /dev/null > ~/scr.txt) Overrides scr6.txt with contetns of scr.txt (nothing) (cat ~/scr.txt > ...


1

Breaking down each of the steps: touch ~/scratches/scr6.txt If file exists, updates the timestamp to now. If doesn't exist, creates it. cat ~/scr.txt > ~/scratches/scr6.txt Reads ~/scr.txt and writes the contents to ~scratches/scr6.txt cat /dev/null > ~/scr.txt Empties the ~/scr.txt file As mentioned in the comments, using "&&" (AND) ...


-1

In simple words: The touch command is the way to create new, empty files. It is also used to change the timestamps (i.e., dates and times of the most recent access and modification) on existing files and directories. In the first command it creates an empty file named scr6.txt. But in second command it create a file scr6.txt and writes all the contents of ...



Top 50 recent answers are included