Quote:
Originally Posted by Ztcoracat
With the technique of redirecting stdout and stderr to:
/dev/null (which if I understand should be) /dev/zero....is only useful for cron jobs and cron jobs only?
|
Discarding output would normally be done by redirecting to /dev/null. You could get the same (non-)result by redirecting to /dev/zero, but I can't think of any reason to do that other than being deliberately confusing. Discarding of output is most commonly done in scripts, where a command is being run for a purpose other than displaying that output. On occasion, it's useful in an interactive session as well. For example, if you wanted to find all the files under /etc that contain a reference to "localtime", you might run
Code:
grep -r -l localtime /etc
But, if you do that as a non-root user the output will be cluttered by complaints about files and directories for which you lack read permission. To see just the output for places where you
do have read permission and ignore the errors, you discard stderr:
Code:
grep -r -l localtime /etc 2>/dev/null
Quote:
Originally Posted by Ztcoracat
And you mentioned; "mailing it to the user that it ran the job for" Please elaborate so I can comprehend this if you could with my example:
Code:
rm -f $find / rkhunter core & > /dev/zero
Anything with rkhunter core would than be deleted?....Right?
|
As written, that line has so many errors that it's not going to do anything like what you thought it might, and I have no idea where "rkhunter" came into the picture. You were a bit closer in your original posting:
Code:
rm -f $(find / -name core) & > /dev/null
First of all, "& >" (with a space between the two characters) is not the same as the single token "&>" (no space). With the space, the single "&" says to run the preceding command in the background and take the rest of the line as a new command, "> /dev/null", which says to run nothing and redirect its output (of which there would be none) onto /dev/null.
The original code from the HOWTO isn't much better:
Code:
rm -f $(find / -name core) &> /dev/null
OK, that's at least syntactically correct, discarding both stdout and stderr from the
rm command (Of course, the
rm command never writes anything to stdout anyway, but whatever.). Also, stderr from the
find command is
not redirected, so you could still see complaints about unreadable directories and the like. But, the big problem here is that the output from
find is substituted in a way that would make any directory with an embedded space character in its name be passed as two separate arguments to
rm. Any shell wildcard characters in a directory name would also be a problem. I'd send a nastygram to the author of that document, but the document is over 12 years old, and the author is probably long gone.
Now the default in a cronjob is to collect any output that, in an interactive session, would have gone to the terminal and, if there is any such output, send it in an email message to the user that scheduled the job. So in this case, any complaints from
rm would be discarded due to the redirection, but if there were any messages from
find, then a message would be sent.
Quote:
Originally Posted by Ztcoracat
EOF you do mean end of file right?
|
Yes. In a C program using stdio, the manifest constant is named "EOF" and is defined as -1.