Use I/O redirection to send output to a file rather than standard out. If you want all the output from your script to go to a file you would type scriptname > outfile at the command line. The > sign redirects the output to the file outfile. To append output to a file use >>.
You can also use this technique inside your script to direct output to multiple files. For example, if I wanted a logfile with execution status and an output file my script might look something like.
Code:
#!/bin/bash
#
# Writing to files example
#
SUCCESS="success."
FAILURE="failure."
ps -aux > out.txt
let rs=$?
printf "Job was a " > log.txt
if [ $rs = 0 ]
then
printf "%s\n" $SUCCESS >> log.txt
else
printf "%s\n" $FAILURE >> log.txt
fi
Bill