Seem simple enough, will have a play but it won't help my scripting skills

I found the online Cron autoconfigure useful, you enter when and how frequent you want to run the script and it will give the correct format to enter into crontab. Used to have a nice GUI for Cron which was great, but cant remember what it was called now and can't find it online.


Tim H

On 22/04/2025 12:34, Peter Merchant wrote:
On 21/04/2025 18:27, Tim wrote:
Good evening on this damp squid of Easter

I will admit that scripting is not my thing but at times I decide I am going to try and improve my scripting (it is basic).

So here what my issue is, I want to delete some .log file from /var/log so I have a very simple one line script in home/mit/scripts called deletefile.sh

Here is the one liner

find /var/log/ -name "*.log" -type f -mtime +7 -delete

(I have no doubt there a 101 ways to write a one line for this but this is the one I am using)

So my understanding is that it will delete any file with an extension of .log which is older than 7 days

But these are log files in /var/log which requires root access to delete

So if I run my script from cmd line as me a user I get an error message permission denied.

/mit@Thinky:~/scripts$ ./deletefile.sh
bash: ./deletefile.sh: Permission denied/

If I run the script as sudo I get command not found??? What command, because I running as sudo should I be running the script

/mit@Thinky:~/scripts$ sudo ./deletefile.sh
[sudo] password for mit:
sudo: ./deletefile.sh: command not found/

Now I thought that using sudo gave me root access on what ever task I am doing from my own "Home" but that error make me think I need to run the script from root home.

Where have I gone wrong??


Tim H
Periodically I run
sudo journalctl --vacuum-time=2d

This clears old log files and frees space.  Ideally I need to find out how to put this into monthly crontab. Lots of learning left to do.

Peter M.


--
 Next meeting: Online, Jitsi, Tuesday, 2025-05-06 20:00
 Check to whom you are replying
 Meetings, mailing list, IRC, ...  https://dorset.lug.org.uk
 New thread, don't hijack:  mailto:dorset@mailman.lug.org.uk

Reply via email to