Questions tagged [io-redirection]

I/O redirection is used in shell scripting. This feature enables one to take the output of a command and redirect it as an input for another command, or a command can take the input from a file instead of from the standard input stream or from the terminal. The whole process helps connect data streams in various ways.

70 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
5
votes
1answer
511 views

Logging the output of remote commands on multiple ssh servers without delay

I've written a simple bash script that ssh's into 3 hosts (2 remote, 1 my own for testing) and runs a long running gui program that outputs text to the terminal that I'd like to log. #!/bin/bash ssh ...
4
votes
1answer
1k views

KSH styling text based menu using STDERR

Is it possible to format the STDERR in order to have a better looking menu using the select command? I have a simple select select oChoice in $(<tempMenu.menu) ; do case "$oChoice" in ...
3
votes
2answers
4k views

Log the output of Expect command

I have made the below expect script and I need to log the output of that script. SOURCE_FILE=`ls -l *.txt --time-style=+%D | grep ${DT} | grep -v '^d' | awk '{print $NF}' ` if [ -n "${SOURCE_FILE}" ] ...
3
votes
1answer
718 views

How to grab mplayer output to file?

I need something like this: When I'll redirect command by FIFO to mplayer echo "get_property volume" > /tmp/fifo I want to have this command output in output.txt, e.g ANS_volume=100. I have ...
2
votes
1answer
78 views

Open output of a command using libreoffice

I am running certain commands in a loop and would like to open its output in libreoffice (calc), without storing it. This is what I have tried: libreoffice --calc <(process m n) libreoffice --...
2
votes
1answer
97 views

concurrent processing in bash using process expansion, and redirection

Apart from possible races that have to be controlled by using proper synchronisation, it's possible in bash to feed a data source concurrently into multiple pipelines and collect all their outputs ...
2
votes
1answer
93 views

Why can you not redirect to files correctly when you swap stdout and stderr by not using Grouping command?

I tried to swap stdout and stderr and redirect each stream to the files, in bash interactive shell. By using brace Grouping command, I gained the output what I want. But I do not understand why when ...
2
votes
0answers
90 views

How to control mysql with zpty?

I try to write a wrapper script for the mysql console client. While working on this, I stumbled upon zpty. It seems perfect. My first goal was to retrieve some table contents, but I already fail ...
2
votes
1answer
125 views

Save output of every command to separate log files?

I would like to tee output of every interactively executed command to a series of separate log files, one for each command. To do so, I have written the following script which will be set up as the ...
2
votes
0answers
812 views

Redirect stdout of a Windows command line program under wine

I run a Windows command line program (that I can not make accessible) with wine. It apparently writes something to stdout and I'm trying to capture that output, but I can't redirect it. No matter if ...
2
votes
0answers
1k views

Recording shell output for interactive commands

While looking into a shell redirection problem, I found a couple of answers that pointed me to the script command. As I understand it, script just records in- and output of the terminal, and allows me ...
2
votes
1answer
465 views

Capturing data from a Fluke 1620a via Bash /dev/tcp file descriptor

I am currently trying to develop a script that will connect to a Fluke DewK 1620a Themo-Hygrometer and pull the current temperature and humidity readings from the device. While these devices have a ...
1
vote
0answers
33 views

Redirect file path for specific executable?

Assume the I have an executable a.exe which wants to accecss path /aaa/bbb/ but has no permission. Is there any way to make a.exe feel for example~/bbb/ like /aaa/bbb/? i.e., something like a ...
1
vote
0answers
41 views

How can 0<&202- be used in Bash to duplicate input file descriptor, when 202 is not a file descriptor?

I sometimes see Bash reverse shells as the following, where the pseudo file /dev/tcp/IP/PORT is used in conjunction with redirection (duplication of file descriptors): 0<&202-;exec 202<>/...
1
vote
1answer
38 views

Redirection to named file descriptor buggy inside functions

Bash has a feature where it will pick a file descriptor number for you and assign it to a variable. $ exec {fd}>foo.txt $ echo "$fd" 11 $ echo "bar" >&$fd $ cat foo.txt bar This feature ...
1
vote
0answers
42 views

Shell redirection - follow name, not a descriptor

I have a shell script that is run in the background and the only thing it does is run 1 command, STDOUT of which is being appended to a file. my_blocking_command >> my_file I want to stop the ...
1
vote
0answers
293 views

Log python http server output to file

I want to start a python webserver in the background and log all of its output to file. Instead the the servers output appears in the terminal. Even tho i guess this is pretty basic ... I've got no ...
1
vote
0answers
32 views

Retaining data in a named pipe after an incomplete read access

Prerequisites: $ mkfifo pipe1 If several lines are put into pipe1 $ (echo line 1; echo line 2) > pipe1 all the lines can be read in another terminal by $ cat pipe1 line 1 line 2 So far all ...
1
vote
0answers
104 views

How to stop python-based borg backup from logging with ^M

I'm trying to make a log file for monitoring backup progress using borg deduplicating archiver. While I am logging, the file contains ^M control characters for each line despite running the script on ...
1
vote
0answers
268 views

iperf daemon not outputting anything to log file

According to documentation, iperf (v2) server can be run in daemon mode and send its output to a log file like this: iperf -s -D > iperflog I'm running that command exactly, as a regular user, ...
1
vote
0answers
1k views

Restoring tty correctly with stty

I'm writing a bash script to read some user input (like a password request), and I'd like to capture the result and pass it through its stdout. (I'm working in a GNU/Linux environment, with recent ...
1
vote
1answer
578 views

Still no output from redirection in a cron job

Every answer to the question of why a cron job results in a zero-length file comes down to using classic output redirection. That still doesn't help, here. # cat /etc/cron.d/aide SHELL=/bin/bash 48 ...
1
vote
0answers
72 views

Redirect the output to an already running program

I have a program running on terminal 1 and waiting for input from stdin. I programmed this program so it is vulnerable to buffer-overflow. I want to change it's flow to function2() within the program ...
1
vote
0answers
501 views

How can I send stdout to multiple commands in fish shell?

Same question as How can I send stdout to multiple commands? but for fish shell.
1
vote
1answer
158 views

find command output empty when redirected to a file

I am trying to obtain a list of files using the find command as follows: find . \( -iname @eaDir -o -iname .DS_Store -o -iname Thumbs.db \) -prune -o -mtime -25 -type f -printf "%P\n" This is ...
1
vote
0answers
38 views

Redirect output to stdall.log, stderr.log and stdoutput.log + return status code

I'm already searched for it and found a solution for it here, but without return status code part. As you can see it uses a sub-shells and I can't get a status code from there, so basing on this ...
1
vote
1answer
463 views

Using input from two different files in a for loop

I have a list of files that I want to search across a list of database tables: [root@host hs]# head -n 3 tables rec_playinth120116 rec_playinth120216 rec_playinth120316 [root@host hs]# head -n 3 ...
1
vote
0answers
48 views

STDERR redirection without intermediate file

Here is a toy shell script: #!/bin/bash set -e misspelled_command exec > run_$( date +%Y%m%d ).log 2>&1 echo "Logging" exit If I submit with nohup bash raise_errors.sh > /dev/null 2&...
1
vote
1answer
297 views

Weird results of triple piping to STDOUT & tee /dev/null >(wc -l > tmp.txt) & piping again embedding `cat tmp.txt`

$ seq 1 12773 | tee /dev/null >(wc -l > tmp.txt) | head -$((0x`openssl rand -hex 7` % `cat tmp.txt` + 1))|tail -1 --> 8473 (random between 1~12773) $ cat tmp.txt --> 8473 $ seq 1 12774 | tee ...
1
vote
0answers
524 views

Failed solution from “How to redirect stdout and stderr to a file and display stderr to console”

First, please refer to How to redirect stdout and stderr to a file and display stderr to console This solution worked wonders for me. I invoked both scripts and commands as the command passed to ...
1
vote
0answers
118 views

Use shell redirection to pre-enter text into an interactive command?

Just to say it up front: I am aware that most programs that have an interactive prompt also have some kind of initialization file or the ability to set a command flag that will run something, and then ...
1
vote
0answers
432 views

How to send supervise stdout to multilog and a second process

I have a process that runs via supervise. I am logging the output via log/run which is using multilog so the log output ends up in log/main/current. I also want to pipe the output into a second ...
1
vote
1answer
437 views

Avoiding Buffering With Output Redirection

I'm trying to write some functions I can utilize in my scripts to essentially tag all output as Error vs Standard output, throw date/time stamps on it, and also include the name of the function that ...
1
vote
0answers
277 views

How to limit/monitor a cgroup process's blkio when process has output redirection

I have some questions on cgroup blkio controller. I want to limit the IOPS on a specific process. This process uses IO redirection to write the stdout contents into a file. I tried to put the ...
1
vote
0answers
599 views

extract text to csv file from output of reading multiple files into specific rows

I am trying to write a bash script to generate a csv file from text within multiple pdf documents. I have a script for converting pdf to text, but not for generating the csv file. Each text document ...
1
vote
0answers
168 views

Inherit IO redirections from a script to another

When I redirect the output of a script within a script, I expect the redirection to be applied to the called script as well as the program called within it. A: ./B 2>> error.log B: ./...
1
vote
2answers
988 views

CSH and all output (with errors) to file

I need save all output from compilation to file. I have many errors "undefined reference" and I want see all of these errors. I try "makeall >& out", but in file "out" aren't any of error "...
1
vote
0answers
872 views

Why the output is not written to log from expect script

I am trying to write the output of the netcat command including the command also to a file by logging into remote servers. But it is not writing. What am I missing ? #!/usr/bin/expect -f set user [...
0
votes
0answers
30 views

How can I redirect a long key press to a device file in bash?

I need a long key press to be redirected to a device file. If I send the same key multiple times, it is considered as separate key inputs (with carrige return). I just need one long key press. How can ...
0
votes
0answers
11 views

Redirect ldapsearch ldiff from Docker container to host while displaying password promt

Having an ApacheDS LDAP DC in a Docker container, I want to export it as ldiff to the host (not inside the container): docker exec -it apache-ds sh -c 'ldapsearch -D "uid=admin,ou=system" -W -p 10389 ...
0
votes
0answers
37 views

How to work with file descriptors stored in variables?

For example, if I assign TWO=2 ...the following fails (with date: invalid date '2'): date >> logfile $TWO>&1 Of course, I can always do eval "date >> logfile $TWO>&1" ...
0
votes
0answers
103 views

rsync send all output to /dev/null

I have the following bash command rsync -q host:/usr/files/client.txt /home/myuser/ 2>&1>/dev/null But it's still giving me Unexpected local arg: /home/myuser/ If arg is a remote file/dir,...
0
votes
0answers
24 views

Redirect output of a long running process to a new log file each day

We have a long running process1 whose output is captured into a log file based on when the process is started: export LOG_FILE=${LOGS_DIR}/$LOGNAME/${LOGNAME}-`date +%Y%m%d-%H%M%S`.txt ... ${...
0
votes
0answers
88 views

send hex as characters to output to remote end

I'm doing a project for a microcontroller that involves sending and receiving special (non-printable character) data through its serial port. I found myself a simulator (ucsim) so I can test things ...
0
votes
0answers
25 views

save input and output data has passed in adb

i want save all input and output commands has executed in adbd I tried to pull adbd file in sbin folder and extract it to modify and Implement of the idea to write a few lines for create file and do ...
0
votes
0answers
79 views

Redirecting input bash

I have a program, that runs on only one Raspberry Pi, but could be run from multiple other computers (through SSH). When I run my program on the Pi, it runs as expected. To be able to run from ...
0
votes
0answers
259 views

Cannot pass argument through /proc/<pid>/fd/0

I have written a basic C++ program as such: #include <sstream> #include <unistd.h> #include <cstdio> #include <iostream> int main(void) { int foo; std::cin >> foo; ...
0
votes
1answer
632 views

How to redirect output to file to STDOUT?

Similar problem as here How to redirect output from file to stdout? However, the solution given there is not universal. My problem: I have a command that produces output to STDOUT. At the same time, ...
0
votes
0answers
59 views

Logging output of scripts called inside another script

Inside bashscript, I am using exec and tee to redirect logs to stdout and a log file in the same time - Unix & Linux Stack Exchange. exec &> >(tee -a "${LogFile}") I am sourcing ...
0
votes
1answer
48 views

Grepping account names (read from a file) from a set of compressed files

This script: while read ACCT ; do echo $ACCT zgrep -h ^$ACCT datafile.0[2-3]2015.gz >>/tmp/$ACCT.txt done < /account_list.txt I get no redirected output file When I remove '>>/tmp/$...