0

I'm using the following command to write the output of a cron job to a file.

python manage.py do_something >> /var/log/do_something_log.txt 2>&1

I want to have the Unix timestamp prepended to the name of the file, something like,

python manage.py do_something >> /var/log/{{timestamp}}_do_something_log.txt 2>&1

I tried,

python manage.py do_something >> /var/log/'date + %s'_do_something_log.txt 2>&1

but this doesn't work.

What can I try next?

3
  • 1
    Replace 'date +%s' with "$(date +%s)" and should work fine. This works fine in my bash: echo hi >./test"$(date +%s)".txt; ls *.txt Commented Dec 9, 2018 at 20:57
  • 2
    'date ...' is not the same as `date ...`. Commented Dec 9, 2018 at 20:59
  • @GeorgeVasiliou that worked for me, You might want to put that as an answer. Commented Dec 9, 2018 at 21:04

1 Answer 1

1

This Will Work:

 python manage.py do_something >> /var/log/$(date +%Y)_do_something_log.txt 2>&1

Output: /var/log/2018_do_something_log.txt

With %s instead:

python manage.py do_something >> /var/log/$(date +%s)_do_something_log.txt 2>&1

Output: /var/log/1544438322_do_something_log.txt

Sign up to request clarification or add additional context in comments.

1 Comment

you should quote the filename.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.