bash - output all to file

Writing script might not be only wants to shows the result on the screen. Some times, we want the script to output to a file. Not only result, but also the errors. Result of cause we want to the know, but errors is valuable also, when we need it to debug the script. Or even warn us of some thing in between the commands is having error, worse, symptoms of system / program failure.

Problem :

Pipe or output all error or status to a file

Solution :

<command> > myoutputfile.log 2>&1
/usr/sbin/ntpdate 0.pool.ntp.org  >> status.log 2>&1


/usr/sbin/ntpdate 0.pool.ntp.org  > /dev/null 2>&1

Viola !!!

No comments: