io redirection is the process of changing where the output and input of a program originate

learn more… | top users | synonyms (1)

0
votes
1answer
179 views

Bash shell with problematic outcomes under Linux (C) [closed]

Following my previous post, I still have one annoying bug that won't leave . I wrote a simulator for the bash command under Linux. When I run my code in a single run, with the these commands: ls ...
5
votes
3answers
1k views

Why `> my.log 2>&1 &` causes the job to sustain log out?

I use myscript > my.log 2>&1 & to run a script and collect it's output - so that when I logout - the script will still be running. It I were to start it with myscript & - it will ...
2
votes
1answer
335 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
383 views

How to add a line to a file which has only root write permission and to continue the script execution

I am trying to learn bash scripting. I am working on a practical problem and at one point I need to add a line to a file which requires root permission to write. The code looks like this: # some ...
10
votes
2answers
344 views

Order of redirections

I don't quite understand how the computer reads this command. cat file1 file2 1> file.txt 2>&1 If I understand, 2>&1 simply redirect Standard Error to Standard Output. By that ...
0
votes
2answers
2k views

Shell script how to read input from a file [closed]

I need to read input from a file given in following format. $ ./process_data.sh arg1 < input_data.txt How do I read input_data in my shell script process_data.sh?
2
votes
4answers
2k views

Change password in headless mode

I am building a script to fully automate a VPS setup, and I need to change the root password. I would like to avoid typing it as the script is running through SSH. Is there a way to redirect an ...
2
votes
1answer
92 views

pipe and log STDOUT at the same time

Some programs output very detailed data, for readability I use awk to filter them. ./output_many_things | awk '{print $1 "\t" $2}' But I don't want to miss anything. Could I redirect the complete ...
4
votes
3answers
633 views

What does the following Bash script mean/do?

What does the following script mean? exec 4<&0 0</etc/XX/cfg read line1 exec 0<&4 UPDATE Thanks for the answer, just one part I'm not sure: It redirects fd0 to fd4, and ...
4
votes
1answer
245 views

command like wc but with tee behaviour

I want to backup a database using psql and COPY command. here is my script: psql "user=${USERNAME} host=${HOSTNAME} dbname=${DBNAME} password=${PASSWORD}" -c \ "COPY (SELECT * FROM tbl) ORDER BY id ...
4
votes
2answers
2k views

stderr redirection not working in csh

I run the following command: pkg_add emacs-23.4,2.tbz 2> output.log The output still displays in the terminal. When I press ↑, I get pkg_add emacs-23.4,2.tbz 2 > output.log with a space ...
3
votes
1answer
1k views

Why does sftp hide the log from stdout?

I have a script a.sh, which has an sftp command: echo "Starting to sftp..." sftp xxx@xxx.xxx.xxx.xx << END_SCRIPT ls mput *.csv.gz bye END_SCRIPT echo "Sftp successfully." If I run it ...
3
votes
1answer
365 views

Redirecting/grep'ing an existing shell's STDOUT

I run a lot of long running processes (simulations) that print progress to STDOUT. I occasionally forget to redirect to STDOUT to a file I can grep, and it's usually too far along to restart. ...
5
votes
2answers
4k views

tail program output to file in Linux

I know we can use below format to redirect the screen output to a file: $ your_program > /tmp/output.txt However when I used below command, it says "-bash: /home/user/errors.txt: Permission ...
2
votes
1answer
1k views

“>/dev/null 2>&1” in `if` statement

I don't understand the below if condition. I know that /dev/null 2 > &1 is sending output to error stream (please correct me if I am wrong). But I don't get it when it is in an if condition ...
4
votes
3answers
506 views

Why do I keep destroying my text files?

I have destroyed a bunch of non-essential files and I don't know why. I have been executing commands like: tr -sc 'A-Za-z' '\n' > somefile.txt | less there is no output (blank page with flashing ...
6
votes
1answer
1k views

Bash read command and stdin redirection

As I understand the bash documentation both | and < redirect stdin. So, cmd | foo and foo < <(cmd) should be more or less equivalent. However, for the bash-internal read command this doesn't ...
4
votes
2answers
3k views

Can I redirect logfiles to syslog?

I have a Node.js server that is being monitored by forever. Forever generates three logfiles: the server STDOUT, STDERR and the log of forever itself. $ forever -l forever.log -o out.log -e err.log ...
3
votes
1answer
303 views

Shell script doesn't paint last line of stdout to screen without user input

I have a shell script that's happily doing all my backup process and writing progress to stderr and stdout, with one exception — the last line doesn't get written to my terminal (if I call the script ...
2
votes
4answers
916 views

Grep for a string with list of files as source

I have a plain text file, in every line is a path to a file. Now I have to grep for a string in these files. Is there any way to use this file as "search source" for grep? Or do I have to copy and ...
1
vote
1answer
982 views

How can I send data to the STDIN of a background process?

I'm trying to: Launch several ssh sessions (processes) through a script (Python) Communicate with the sessions by sending them commands via STDIN (even though they aren't open in my current ...
6
votes
2answers
3k views

what is meant by connecting STDOUT and STDIN?

This is a newbie question. I'm reading a book, it says: Every process has at least three communication channels available to it: “standard input” (STDIN), “standard output” (STDOUT), and ...
0
votes
3answers
7k views

How do I redirect command output to a file?

I have a command that I run in a folder that outputs MD5 hashes and filenames on the terminal: ls |sort -nr | xargs md5sum I need this output in a text file that I can download and compare to ...
1
vote
3answers
2k views

permission denied when redirecting sudo sed output [duplicate]

Possible Duplicate: Redirecting stdout to a file you don't have write permission on I'm trying to install drupal according to the instructions given in this tutorial: ...
3
votes
1answer
765 views

find with multiple -exec options; redirecting &>/dev/null for one exec command sends process to background

I have a find command with multiple -exec arguments and would like the output (both stdout and stderr) for one of the commands to be suppressed. When I use &>/path/to/file, it sends the process to ...
6
votes
2answers
2k views

Logging ALL stderr output of crontab to file

For example, I can log stderr of one script in this way: * * * * * run_script.sh > /var/log.txt 2>&1 But I want to log stderr of all scripts in my crontab. I can append > /var/log.txt ...
7
votes
3answers
4k views

bash: Use a variable to store stderr|stdout redirection

Is there any way to redirect stdout and stderr via variable like adding command options in script? For example I have a script: #!/bin/bash -x TEST=">/dev/null 2>&1" OPT='-p -v' mkdir $OPT ...
27
votes
4answers
10k views

How can I send stdout to multiple commands?

There are some commands which filter or act on input, and then pass it along as output, I think usually to stdout - but some commands will just take the stdin and do whatever they do with it, and ...
4
votes
2answers
1k views

the usage of < /dev/null & in the command line

I tried to run an example java program using the following command line. However, I do not know what is the trailing part < /dev/null & used for? java -cp /home/weka.jar ...
1
vote
3answers
327 views

Customize the way stderr is appended to a file

I have an issue with a shell script that uses rsync to synchronize 2 directories. I'm storing the result of the rsync command (whether it's successful or not) to a file named status and in case there ...
2
votes
1answer
1k views

Diff the output of two `awk` commands

I'm trying to compute the difference between the output of two awk commands but my simple attempts at it seem to be failing. Here is what I'm trying: diff $(awk '{print $3}' f1.txt | sort -u) $(awk ...
0
votes
1answer
115 views

Applying an IO redirection&audio device example in Fedora

Here is an example I saw in a webpage which uses IO redirection to make the audio device make sound. less sound.wav > /dev/audio But I cannot do it in Fedora. It outputs the input data format is ...
6
votes
4answers
10k views

How to read from two input files using while loop

I wanted to know if there is any way of reading from two input files in a nested while loop one line at a time. For example, lets say I have two files FileA and FileB. FileA: [jaypal:~/Temp] cat ...
11
votes
3answers
2k views

How can I pipe output to another process, but retain the error state of the first process? [duplicate]

Possible Duplicate: Get exit code of process that's piped to another I am using the following command line (in a makefile) to pipe the verbose error messages from my compiler through a ...
13
votes
1answer
435 views

Grep alias - line numbers unless it's in a pipeline

I want to create a bash alias for grep that adds line numbers: alias grep='grep -n' But that, of course, adds line numbers to pipelines as well. Most of the time (and no exceptions come to mind) I ...
1
vote
3answers
582 views

No output to log from tee when starting mplayer as an arg to gnome-terminal

I want to view mplayer's normal terminal output, and also write it to a log. That works fine when I run mplayer from the commandline, eg: mplayer "$HOME/gdr01.wav" 2>&1 |tee $HOME/junk.log ...
12
votes
3answers
306 views

How to redirect whatever I enter in terminal to file

I am a novice just learning Fedora 13. I just wanted to know if its possible to redirect whatever I type in the terminal to a file, so that I would be able to see from the file, that a particular ...
7
votes
3answers
1k views

Piping STDERR vs. STDOUT

According to "Linux: The Complete Reference 6th Edition" (pg. 44), you can pipe only STDERR using the |& redirection symbols. I've written a pretty simple script to test this: #!/bin/bash echo ...
22
votes
3answers
7k views

Reading lines from a file with bash: for vs. while

I'm trying to read a text file and do something with each line, using a bash script. So, I have a list that looks like this: server1 server2 server3 server4 I thought I could loop over this using ...
20
votes
1answer
5k views

Why is redirecting STDERR to /dev/null done this way?

This does not make sense to me. wibble > /dev/null 2>&1 I think it would make more sense if it was something like this: wibble 2>&1 > /dev/null In other words Commands ...
9
votes
3answers
4k views

Non-blocking buffered named pipe?

I'm looking for something I suspect doesn't exist: A non-blocking buffered named pipe (fifo) for use from the command line. Is there such a thing? Here's the use case: Suppose I have a process that's ...
21
votes
2answers
1k views

What does a “< <(…)” redirection mean?

I've seen that rvm (ruby version manager) is installed using the following command: bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer ) So as I ...
11
votes
6answers
5k views

xargs with stdin/stdout redirection

I would like to run: ./a.out < x.dat > x.ans for each *.dat file in the directory A. Sure, it could be done by bash/python/whatsoever script, but I like to write sexy one-liner. All I could ...
3
votes
3answers
1k views

Create a temporary file from a stdout redirect or pipe

Some commands only output to stdout. Some tools only work on files. Is there a command that can glue those together? Contrived simple example: diff $(echo 1 | stdout-to-temp-file) $(echo 2 | ...
4
votes
4answers
402 views

ls command operating differently depending on recipient

How does commands like ls know what its stdout is? It seems ls is operating different depending on what the target stdout is. For example if I do: ls /home/matt/tmp the result is: a.txt b.txt ...
2
votes
2answers
829 views

Difference between > and | with /dev/tty

When I run this command: echo "1" > /dev/tty # runs successfully but when I run this: echo "1" | /dev/tty #permission denied What is the difference between these two operators > and | and ...
6
votes
2answers
1k views

How to send input to a C program using a shell script

I have a C program in which I use scanf to get user input. Now, I would like to make a .sh script that automatically test this program with pre-defined user input, but I'm not sure how I can send the ...
4
votes
2answers
139 views

Unable to capture program exit

I started a program written using Node.js and started it using launch pipe into logfile and send it to background. Half way running the program exited w/o any error both on the console nor the log, I ...
9
votes
4answers
11k views

Difference between 2>&1 > output.log and 2>&1 | tee output.log

I wanted to know the difference between the following two commands 2>&1 > output.log and 2>&1 | tee output.log I saw one of my colleague use second option to redirect. I know ...
14
votes
2answers
6k views

View stdout/stderr of systemd service

I have created a simple systemd service file for a custom application. The application works well when I run it manually, but my CPU gets maxed out when I run it with systemd. I'm trying do track ...