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
--
 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