I want to make a crontab, which would write content with format name like this :
content_YYYYMMDD_HHmmSS.txt // for example: log_20170811_1706.txt
Please help me. I'm Linux novice.
I want to make a crontab, which would write content with format name like this :
content_YYYYMMDD_HHmmSS.txt // for example: log_20170811_1706.txt
Please help me. I'm Linux novice.
The crontab is the table of cron-jobs, that are executed by the cron daemon, a process that schedules jobs at the times you give it (https://en.wikipedia.org/wiki/Cron).
In order to write something into a file, you'll have to run crontab -e
in order to edit the crontab (see also How do I set up a Cron job?).
In order to write to into a file, which contains the date as name, you'll have to use the date command. For example, date +"%Y%d%m"
prints what one would call YYYYMMDD. You can get the details of the date format in man date
.
All in all, you'll have to write something like
* * * * * echo "Test" > "/home/myuser/content_"$(date +"\%Y\%d\%m")".txt"
to write every minute "Test" into the file of its current date (EDIT: like suggested by steeldriver, you have to escape the %, instead it will be interpreted as newline by cron). You should have a eye on the fact that this is executed as your user, so you should write in a directory where you have rights to write.