The general rule is " >> file 2>&1 " to capture both, one (stdout) first, then 2 (stderr).
Very occasionally, you will see/do these in the opposite order, and it is not always a mistake (just usually), to send stdout to a file and stderr down a pipeline. If the app writes to (or reads from) an fd opened on /dev/tty, then you are into the land of expect/rsh/ssh to create a pseudo/remote tty you can recapture onto stdout.
Keeping the controlling terminal mapped to /dev/tty, FILE*'s: stdin, stdout, stderr, fd's: 0, 1, 2 ; cooked and uncooked tty input and output all straight and separate is one of those classic initial UNIX learning tasks.
Putting both into one file is popular: you do no care which wrote what, no research, one or no files, and you can grep or otherwise process the output to see if you got what you wanted and discard the rest. You might do something like this for simplicity and volume efficiency:
This way, you do an nslookup for each ip and frame the output for each. One sed can collect all the lines for one ip into the buffer using that framing, and then ( . . . = depends on what your nslookup writes and what you want) you can make it into whatever you want. The only file you make is the output file -- no cleanup, no old data, no file name creation or collisions, no running out of space with big data sets.
---------- Post updated at 03:35 PM ---------- Previous update was at 02:41 PM ----------
PS: nslookup has an interactive command mode, so you can use one nslookup if you generate commands to it equivalent to the command line args, and avoid calling it so many times.
@DGPickett
Under what unix O/S does nslookup react correctly to the Shell redirects like "2>&1". It is one of the very few programs where I had to use unusual techniques.
Imho unix "nslookup" just ignores unix I/O conventions.
Btw. Scripting a unix "nslookup" global enquiry and saving the results is not hard work. The secret there is not to try to redirect the output in Shell but to use the output functions in "nslookup" itself.
There almost certainly will be issues with listing the contents of a remote Internet Name Server because most of them block such enquiries.
Yes, zone inquiry is no longer considered innocent!
nslookup is not a mainstream tool, and like many somewhat admin-level tools, it not so user friendly. For the casual user, learning the various query methods and output formats is a bit of a pain. They might be better served doing getpeername, gethostbyname and such in C, JAVA or PERL.
Last edited by DGPickett; 01-09-2011 at 11:00 PM..
Hi -
I am looking for a replacing a string in a in multiple *.sql files in directory with a new string without using a temporary file
Normally I can use sed command as below
for W in ls `FILE*.sql`
do
sed 's/OLD/NEW/g' $W > TEMPFILE.dat
mv TEMPFILE.dat $W
done
But Here in my... (9 Replies)
Hi all..
The following set of statements is used in a shell script to ftp a file to a remote machine
I want to redirect the ftp messages thrown by the first ftp statement to a log file. As you can see there is a logic downstream to decide if the ftp was a success or not. But i am not... (5 Replies)
Hi all.
I want to check the free space on a given FS and process the output. Right now, I'm using a temp file to avoid using df twice. This is what I'm doing
#!/usr/bin/ksh
...
df -k $FS_NAME > $TMP_FILE 2>&1
if ]; then
RESULT="CRITICAL - $(cat $TMP_FILE)"
else
cat $TMP_FILE | ...... (3 Replies)
summary found at bottom. to skip straight to action summary, ctrl+f for <summary>
this initially started with trouble changing passwords due to client being unable to authenticate, this was further caused by missing client files.
This was transparent to me, so this details the road I took,... (0 Replies)
I'm trying to read mail but I obtained this message:
msgcnt 2446 vxfs: mesg 001: vx_nospace - /dev/vg00/lvol4 file system full (1 block extent)
mail: no space for temp file
I want to empty my mailbox
How could I make this?
Regards
Leonardo Siza (3 Replies)
Hello All,
I was wondering is there any other way in Shell Scripting to redirect the errors to a output file inside a shell script with using a error status checking or a command line redirection.
Say without doing this
ksh test.ksh 2> error.txt
or without doing this ...
if ; then... (3 Replies)
Hello,
I am New to Unix.
I am Using HP-UX 9000 Series for my Application.
I am Currently Facing an Issue that the error messages are being written in the syslog file instead of the Application Log File. The Codes for that Syslog.h is written in Pro*C.
I want to know how to Redirect these... (3 Replies)
Hi,
I am new in shell scripting.
Can anyone point out what wrong of below script.
If I want the error output to "sqlerror.log"
and database pool data output to "bulk_main.dat".
Right now, the below script, if successful execute, the data will output to
bulk_main.dat && sqlerror.log both... (7 Replies)