Tag Info

New answers tagged

2

Common mistake, wrong order of redirection, try this: … sendmail_alive.sh >/tmp/sendmail_alive.log 2>&1 It works like this: file descriptor stdout to /tmp/sendmail_alive.log file descriptor stderr to the value of stdout (/tmp/sendmail_alive.log) With your order, you first point the stderr where originally was stdout and you get the stderr ...


1

Linux specific: echo |perl -e '$p=getppid; `echo foo > /proc/$p/fd/2`' If you here redirect stderr 'foo' is still printed on the terminal: echo |perl -e '$p=getppid; `echo foo > /proc/$p/fd/2`' 2>/dev/null


4

Just use redirection operator > at the first line: sqlplus -s "/nolog" <<EOF >logfile conn / as sysdba @?/sqlpatch/19282021/postinstall.sql exit; EOF You can also write >logfile at the beginning of the line, what is equally legal syntax in most shells, but less commonly practiced. >logfile sqlplus -s "/nolog" <<EOF conn / as ...


2

From OpenSSH readpassphrase.c, line 75: /* * Read and write to /dev/tty if available. If not, read from * stdin and write to stderr unless a tty is required. */ The program reads and writes the TTY directly hence it's not possible to disable direct input by just closing the standard input and output pipes. You have to tell the SSH ...


4

You don't need the cat. sed happily accepts the file name as argument: sed 's/^ *//' <file> If you use GNU sed you can use the -i or --in-place switch to edit the file in place: sed -i 's/^ *//' <file> To answer the question, you can achieve “full file buffering” using the tool sponge from the moreutils package. Using sponge you can do: ...


0

Useless use of the cat command. Use sed directly to print the contents or use -i to do an in place edit.


0

One other possibility is to put the entire contents of a file into a shell variable. There used to be a limit on the size, but I understand that this is no longer a problem. As long as you have the memory (of course exceeding physical memory would cause swapping) you can try the following: For example: varx=`cat filename` echo "$varx" | sed ..... ...


0

Have you looked at the Linux buffer command? This utilizes a user shared memory segment to basically allow concurrent reads/writes. I suppose that it could buffer an entire file if the shared memory segment is large enough. The buffer command might not be automatically installed, but I have found the program in many of the repositories on different Linux ...


0

You simply have to use -i switch of (GNU) sed, so sed -i -r 's/^ *//' file_to_replace_in_place.txt and for Os X : sed -i.'' -r 's/^ *//' file_to_replace_in_place.txt Another (more generic) solution is to use tee : cat file | sed 's/^ *//' | tee file you have to take care of huge files, this can exit without error, nor change.


1

For now find . -name '*.php' -exec iconv -f CP1251 -t UTF-8 {} -o {} \; works like a charm


4

Digging around here, I understood from http://unix.stackexchange.com/a/56877/54067 (where both the question and answer are worded differently and the problem is not related to interactive input) that the reason for the problem is that the cp -i expects the user to give the interactive input confirmation via stdin but in the cat | while read loop stdin is ...


0

The following script should do the job. LOG_SIZE=500000 NUM_SEGM=2 while getopts "s:n:" opt; do case "$opt" in s) LOG_SIZE=$OPTARG ;; n) NUM_SEGM=$OPTARG ;; esac done shift $((OPTIND-1)) if [ $# == 0 -o -z "$1" ]; then echo "missing output file argument" exit 1 fi OUT_FILE=$1 shift NUM=1 while :; do dd bs=10 ...


0

There is a clever trick with tee and subshells: cat source.lst | tee >(doSomething.sh) >(somethingElse.sh) | somethingFinal.sh I've done this before pv -perl source.list | tee >(doSomething.sh) >(somethingElse.sh) | md5sum pv will give you a progress bar, an ETA, and a running line total. Then source.lst will be fed to doSomething.sh and ...


0

I'm not sure I'd call it an "answer" per se, but I was able to approximate what I was looking to do in a completely different way. Instead of nc, I've managed to get further along using a file descriptor on /dev/tcp. exec 3<>/dev/tcp/${host}/${port} echo -e "read?" >&3 cat <&3 | tee -a ${log} exec 3<&- exec 3>&- There are ...


1

Store the output of smartctl into a variable and use it as many times as you like. smartctl_output=$(smartctl -a /dev/sda) serial_number=$(printf %s "$smartctl_output" | awk 'sub(/^Serial Number: */,"")') printf %s "$smartctl_output" >"$serial_number.txt"


1

You could use another command (namely lsblk) to get only the serial number of that particular device (so no need to parse smartctl output): smartctl -a /dev/sdb > $(lsblk --nodeps -no serial /dev/sdb)


0

You could just store the output of smartctl -a in a temporary file and then do the double parse on that. This makes testing your script fast (generate the temporary file once, comment out the call to smartctl, adjust your parser until they are satisfactory, then uncomment the smartctl line. Alternatively you can use pee to pipe the output of smartctl -a ...


-5

Whats wrong with simple two line batch file? Like: Cmd1 >filespec Cmd2 <filespec Or cmd1 >filespec cmd2 filespec either way, the file is left in mass storage.


6

The already given answer is correct. But if your goal is to selectively read your verylongfile.txt w/ cmd2, sed might be another option. cmd1 | sed -e 'w verylongfile.txt' -e '/notinteresting/d' | cmd2 sed will write all of its input to the outfile, but only the bits that do not match the /notinteresting/ address to the pipe. Or you might negate the ...


15

As far as I know, cmd1 | tee verylong.txt | cmd2 will not hold the whole file in memory. In fact, if cmd2 was to wait too long before consuming its input, cmd1 might block on a write call and unblock only when cmd2 starts reading again. The reason for that is that there is a buffer for the pipe, and that buffer, by default, is limited to a certain ...



Top 50 recent answers are included