Forums

Remove Old Log Files...

Trying to remove schedule task's old log files but getting permission denied error. There are 100+ log files @ var/log which we need to remove but not successful.

Any suggestion?

Please help.

On your end, you could just use

echo '' > /var/log/logfile

to clear out the file contents.

But to actually delete the files, we would have to do that for you as of right now. Would you like us to delete all scheduled task log files except for the most recent one?

Thanks for the prompt response...

We already executed the command... But Please remove the logs from your end.

I'm not sure if I should have opened a new thread, but I am having the same issue. My webapp has two log files, one for the naked URL and one for www. I would like the ones for the naked URL removed please.

We have a new api endpoint that allows you to remove these logfiles if they are not currently being used by webapps etc. Check out the documentation, get an api token, start a new console, and try to send a DELETE request to www.pythonanywhere.com/api/v0/user/{username}/files/path{path}/

I tried the code below, but it doesn't seem to be working. I'm not too familiar with HTTP methods. Could you provide a little guidance about what I'm doing wrong?

curl --request DELETE --header "Authorization: OAuth PASTED_MY_TOKEN_HERE" http://www.pythonanywhere. com/api/v0/user/0p3r4t0r/files/path/var/log/kgisteam.com.server.log

  1. use https (otherwise anyone listening to your traffic can steal your token! perhaps get a new token if you want to be safe)
  2. what error do you get back when you do that curl?
  3. shouldn't it be Authorization: Token YOURTOKEN?

That did the trick, thanks. It was late at night and I was stuck on old habits. Good call on using https:

Thanks for all of your help. I always appreciate the support of the python anywhere community!

Glad we could help :-)

Hi Team,

I am trying to delete log using below command but it is not working. curl --request DELETE --header "Authorization: Token my_token" https://www.pythonanywhere.com/api/v0/user/rajnath/files/var/log/rajnath.pythonanywhere.com.access.log.5.gz

Please help

What is the output? What error are you getting?

There is a script that does the job. If you pip3 install --user pythonanywhere you could use pa_delete_webapp_logs.py script.

It works like this:

Deletes webapp logs.
- gets list of logs via api
- deletes logs via api
Usage:
  pa_delete_webapp_logs.py [--domain=<domain>] [--log_type=<log_type>] [--log_index=<log_index>]
Options:
  --domain=<domain>         Domain name, eg www.mydomain.com   [default: your-username.pythonanywhere.com]
  --log_type=<log_type>     Log type, could be access, error, server or all   [default: all]
  --log_index=<log_index>   Log index, 0 for current log, 1-9 for one of archive logs or all [default: all]

And here is the code: https://github.com/pythonanywhere/helper_scripts/blob/master/scripts/pa_delete_webapp_logs.py

Thanks for reply but how does it work? I can not find any document. I have installed the library but could not get it work.

What does that mean? Do you get an error? What is the error message?

Hey all, I made a python file that allows you to delete ANY log file by name, you can find it here

This worked perfectly:

curl --request DELETE --header "Authorization: Token PASTED_MY_TOKEN_HERE" https://www.pythonanywhere. com/api/v0/user/my_username_here/files/path/var/log/my_domain_name.com.server.log

@rajnath -- you were probably lacking path in the url -- look at @samtech's solution; you can as well use our helper_scripts package which wraps our beta API, as @jumbocakeyumyum did.

11:52 ~ $ echo '' > /var/log/logfile bash: /var/log/logfile: Permission denied

@tangca Are you sure /var/log/logfile exists?