1
vote
2answers
51 views

Hiding Script Command Output

I'm building a shell script to automatically configure a specific computer with the best settings. I would like to hide all output from this script except for echo output. Is it possible?
1
vote
1answer
59 views

Send copy of a script's output to a file

Say I have a Zsh script and that I would like to let it print output to STDOUT, but also copy (dump) its output to a file in disk. Moreover, the script starts with the following option set -o xtrace ...
1
vote
2answers
103 views

How to properly launch a program and make possible to redirect its running output (stdout and stderr) at a later stage?

The problem is quite simple: I find useful to have the possibility to switch on (and off) the output of some running program in each moment I need. To be more precise I want to be free to redirect ...
8
votes
2answers
130 views

How do I elevate privileges in the middle of pipeline?

My guess was as follows: echo "Generating some text" | su - -c cat >/output/file But su says: su: must be run from a terminal What would you do?
0
votes
1answer
49 views

Capture Error of LS to file [duplicate]

#!/bin/sh if [ $(ls sample01.log | wc -l) = 1 ] then echo "File Found" > lsOutput.log else echo "File Not Found" > lsOutput.log fi But if sample01.log is not already existing my code already ...
1
vote
2answers
74 views

How can I tell what device or file name I am redirecting to

From within a shell script (sh/bash), how can I tell what device or file name I am redirecting to? For example, I have a shell script named script.sh. I run the shell script and redirect STDOUT to a ...
1
vote
1answer
114 views

Bash Script which can direct stdin stream to program

I am trying to create a script capable of infinitely processing an incoming stream which is piped to it, and continuous producing an output stream which can be piped to something else something as ...
5
votes
1answer
320 views

How to append multiple lines to a file without last newline?

I have a very long string that is split in chunks. I want to append them to a file without putting the newline character using bash. Example: First append cat >> abc.sh << EOL echo "bla ...
4
votes
1answer
70 views

What's the difference between sh script and sh < script

What's the difference between sh myscript and sh < myscript I played around and they seem to have the same effect. Are they equivalent?
3
votes
2answers
308 views

How to output to screen overriding redirection

Is it possible, within a shell script, to write to the screen while STDOUT and STDERR is being redirected? I have a shell script that I want to capture STDOUT and STDERR. The script will run for ...
3
votes
3answers
72 views

capture output from command without interference

How can I test whether a command's output is an empty string without interfering with said output? Example: command | ??? if [ $? = 0 ] && [ -n "$output_from_command"]; then ... I'd ...
1
vote
3answers
642 views

Line 4: $data: ambiguous redirect when using passwordbox

I want to create a passwordbox using the dialog package. #!/bin/bash data=$(tempfile 2>/dev/null) trap "rm -f $data" 0 1 2 5 15 dialog --title "Password" \ --clear \ --passwordbox "Enter your ...
5
votes
1answer
68 views

Is it possible to create sticky redirection from stdout/stderr

Consider such code: echo hello >> log.txt echo world >> log.txt I execute command with stdout redirection. Is it possible to create sticky redirection? Something like this: redir ...
2
votes
1answer
103 views

Redirecting an active port

Environment: Web server that requests pages on a specific port from an application server. Problem: If a page request comes into the application server during the restart of a certain web application ...
12
votes
3answers
348 views

When to use redirection to stderr in shell scripts

I know that well-behaved utilities like grep output "normal" messages to stdout, and error messages to stderr. $ grep '^foo' file1 file2 file1:foo grep: file2: No such file or directory When I'm ...
2
votes
3answers
12k views

How to append multiple lines to a file with bash

I am writing a bash script to look for a file if it doesn't exist then create it and append this to it: Host localhost ForwardAgent yes So "line then new line 'tab' then text" I think its a ...
4
votes
4answers
241 views

Can I write the output the of time difference command to a file?

Can I write the output of the time difference command to a file? For example, I tried: $ time foo.sh > bar.txt But it only gives the output of foo.sh to bar.txt.
2
votes
2answers
99 views

What makes the shell interpret these redirects as follows?

Can anyone help me understand this seemingly odd behavior of how the shell parses the redirects..? $ cat > test.txt Line 1 Line 2 $ ls -i dummy.txt dummy2.txt ls: dummy.txt: No such file or ...
1
vote
1answer
457 views

How to ssh on multiple ipaddress and get the output and error on the local *nix machine?

command="ls -lrt;uname -a;uname -o" for i in 10.38.227.229 10.38.164.103 do ssh auto21@$i "$command 2>&1" >> log #ssh -n auto21@$i "$command" 2> >> log done i am trying ...
4
votes
1answer
2k views

SSH causes while loop to stop

I have finally managed to boil down a problem I have been struggling with for a few weeks. I use SSH with "authorized keys" to run commands remotely. All is fine except when I do it in a while loop. ...
2
votes
1answer
482 views

How to wait for a subprocess used for I/O redirection?

Consider the following snippet of Bash script: exec 3> >(sleep 1; echo "$BASHPID: here") do-something-interesting exec 3>&- wait $! echo "$BASHPID: there" When executed, it produces: ...
1
vote
2answers
3k views

How can I get vsftpd version into shell variable?

I want to get vsftpd version into shell variable. I can get it to console with ease: # vsftpd -version vsftpd: version 2.2.2 Also I can get a lot of other info into variable: # i=`bash --version ...
1
vote
2answers
529 views

Print/Tee to console without passing output to pipe

Is there a way to print or tee one thing to the console and still pass something else through to the next pipe? Something like: echo dog | printOrWhatnot "PUTTING MY THING DOWN" | sed 's/dog/cat/g' | ...
3
votes
1answer
549 views

Parameretrize file descriptor number to open a tcp socket in shell script

I'm tried to parameretrize in a variable the file descriptor number to open a tcp socket using exec command but it failed. Only work correctly when file descriptor number is a constant. In the next ...
1
vote
1answer
97 views

Redirection doesn't show up as an argument to a sourced script

My problem is that I can't print to the screen when I write a bash script . myBashScript.sh < text.txt In myBashScript.sh I just print out echo $2 But instead of printing "text.txt", it ...
3
votes
2answers
1k views

exec < filename - what does this do?

I have found the following code snippet (sh): TESTFILE=$TEST_PATH/test.out if [ -f $TESTFILE ] then exec < $TESTFILE else echo "$TEST_PATH: no test.out file" fi ...
0
votes
1answer
213 views

The “cp p2 &2 &” command makes Konsole to disappear, is it a bug?

The goal is start a background process that copies the data from the pipe p2 to the STDOUT as p2 is feed with data by some other process. I guess the command is incorrect. Nevertheless, the Konsole ...
5
votes
3answers
11k views

ssh input from text file

These two question is driving me crazy and I don't have good expertise of ssh. (but I suspect it is to do with redirection only) The questions are, You want to pass multiple lines of input from a ...
6
votes
2answers
4k views

Why does `exec 2>&1` fail in this bourne shell script?

I am porting an old ksh script to Bourne shell. The old ksh script contains the following code: #!/bin/sh tmpLog=/var/tmp/logfile.$$ exec 1> $tmpLog exec 2>&1 eval $* another_command_1 ...
1
vote
2answers
847 views

On the command line, can I redirect output to a file WITHOUT >, >>, or | operators?

I am attempting to run a command on a CentOS virtual machine, and the API that I am using to run this command does not seem to allow the >, >>, or | operators. Also, I must use fully qualified paths ...
1
vote
3answers
284 views

Concise way to output to file if argument is given, to stdout otherwise

I'd like my script to output to stdout unless it gets a filename as an argument. An obvious way is like so: if [ -e "$1" ]; then command_with_output >$1 else command_with_output fi It's ...
1
vote
2answers
2k views

Show command executed along with output in log file

Is there a quick and dirty way to not only log the output of a shell file but the commands used inside as well? For example: whoami > who.dmp would output a file that contained something like: ...
8
votes
1answer
948 views

Suppress output unless non-zero exit code

What's the best way to suppress output (stdout and stderr) unless the program exits with a non-zero code? I'm thinking: quiet_success() { file=/tmp/suppressed if ! ( "$@" > "$file" ...
2
votes
1answer
385 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
1answer
318 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 ...
0
votes
3answers
8k 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 ...
8
votes
4answers
12k 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 ...
1
vote
1answer
779 views

Taking output of /dev/tty into a variable

I created a two backup scripts - one for files (filebackup.sh) and another for database (dbbackup.sh). filebackup.sh calls dbbackup.sh and stores the output in a variable. The output returned by ...
9
votes
1answer
6k views

File descriptors & shell scripting

I am having a very hard time understanding how does one use file descriptors in shell scripts. I know the basics such as exec 5 > /tmp/foo So fd 5 is attached to foo for writing. exec 6 < ...
1
vote
2answers
628 views

writing a command transcript to file

Here is a script from Mercurial issue 2743. Call it mq.sh. I'm trying to get it to do the following things, on Debian squeeze. Echo commands + standard output + standard error to a file. Prefix with ...