I created a simple script that does a curl command ( I run it every month via crontab ) and I made it echo to a logfile with the date of run. The problem is that I want to receive the shell script output as well to the log file and I'm sure quite sure how to achieve that. This is what I have:
#!/bin/bash
#
LOGFILE=/root/Delete-Old-Indices.log
#Nginx Logs - Delete older than 90 Days
curl -XDELETE XXXXXXXXXXXXXXXXXX
echo "$(date "+%d%m%Y %T") : Starting work" >> $LOGFILE 2>&1
so now I only receive the following line of log in my log file: "Date + Time : Starting work" and I don't get the shell script output in my log file, I only see it in my shell window.
Thank you
printf '%(%d%m%Y %T)T : %s\n' -1 "Starting work"
if you intend to print a time stringprintf
is a better choice.