4

I have created batch file which starting & stopping celery services.

I want to implement code in batch file so that files older than week will be deleted.

celery_restart.bat

NET STOP "CeleryBeat"
NET START "CeleryBeat"
NET STOP "Celery2"
NET START "Celery2"
2
  • 2
    What have you tried? Have you considered using logrotate? Why did you use the python tag? Commented Sep 25, 2019 at 6:10
  • 1
    As I am using windows machine so not able to use logrotate so I have created batch file using which I am restarting celery services & able to rotate log file along with also. Celery create new log file every time I am restarting celery services using batch file. Commented Sep 25, 2019 at 6:15

2 Answers 2

2

For Windows:

ForFiles /p "your\folder\with\logs" /m *.log /d -7 /c "cmd /c del @file"

Add /s to delete log files in subfolders as well. If you want to delete all files in the folder older than 7 days, just remove the /m *.log option.

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

2 Comments

above code working. I also want to delete .pid files alongwith log files so is there any way to delete .pid files also with same line because currently I have used two lines one for .log & another for .pid.
I recommend running ForFiles /? from the command line - it's pretty self-explanatory (literally). However to do what you want, there's no easy option - that question is answered here: stackoverflow.com/questions/11719347/… (I would prefer the first solution given).
0

Or you can just run some for loops:

@echo off
set comms="CeleryBeat" "Celery2"
for %%i in (*.pid *.log do del %%i /Y
for %%a in (%comms%) do (
    net stop %%a && net start %%a
)

the && operator here will start the service only if the previous command exited with errorlevel 0

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.