0

I have a PowerShell script that receives live log data and writes it into a file which contains a timestamp in the filename. Locally my script is running fine but when I run it in a docker container I get the following error message:

Out-File: /app/myscript.ps1:13

Could not find a part of the path
     | '/app/myapp-logs/live-logfile-10/05/2022-14/12.txt'. 

Here the relevant line of my code:

cf logs myapp > ".\myapp-logs\live-logfile-$(Get-Date -Format "dd/MM/yyyy-HH/mm").txt"

I'm using the latest ubuntu base image and the Powershell Version: 7.2.3-1.deb.

2
  • Use something other than / as the separator in the datetime format, eg. $(Get-Date -Format "dd_MM_yyyy-HH_mm") :) Commented May 10, 2022 at 14:34
  • Refer this link stackoverflow.com/questions/1954203/… Commented May 10, 2022 at 14:41

1 Answer 1

0

The error you receive is because you're trying to write to a file in a subdirectory underneath /app/myapp-logs/live-logfile-10/ - and the directory live-logfile-10 doesn't exist.

Use something that isn't a slash in the datetime format used and the problem will go away:

cf logs myapp > ".\myapp-logs\live-logfile-$(Get-Date -Format "dd_MM_yyyy-HH_mm").txt"  

That being said, I'd recommend using a big-endian datetime format - this will make it much easier to sort the log files by date:

cf logs myapp > ".\myapp-logs\live-logfile-$(Get-Date -Format "yyyyMMdd-HHmm").txt"
Sign up to request clarification or add additional context in comments.

Comments

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.