I just want to to redirect my script output to a file, to do so I try to redirect the output of a simple command and it works for a particular syntax and not for the other. Could you please have a look and give me any advice, Thanks in advance. Rgds, O.
This one is working fine:
du -h > "/var/log/mytst.$(date +%Y-%m-%d_%H:%M).log"
and this doesn't:
du -h > /var/log/mytst."$(date +"%D--%H:%M:%S")".log 2>&1
Any idea?
For utilizing the redirection of bash, execute any script, then define the > or >> operator followed by the file path to which the output should be redirected. “>>” operator is used for utilizing the command's output to a file, including the output to the file's current contents.
Look at this output:
$ echo "/var/log/mytst.$(date +%Y-%m-%d_%H:%M).log"
/var/log/mytst.2014-08-11_13:54.log
$ echo /var/log/mytst."$(date +"%D--%H:%M:%S")".log
/var/log/mytst.08/11/14--13:54:00.log
The second one spects a tree hierarchy, as the /
's in the output of date +%D
are treated as directory separators. Your question does not state how the second version 'does not work', so I would bet the error is No such file or directory
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With