I'm getting the strong feeling that...

L Carver

New Member
Joined
Sep 29, 2018
Messages
4
Reaction score
2
Credits
0
...every script I write/rewrite since installing a newer Kubuntu is written wrong from the start.

The one I'm having trouble with now is
  • supposed to delete text files ending in .log
  • failing to do this one simple thing.
My script:
Code:
#!/bin/bash

echo "This script will remove .log files from the current directory."

   rm -v "*log" 2>/dev/null
#   rm -v "*log" 1>/dev/null

    echo "Done."
exit 0
Returns (in stout):
Code:
This script will remove .log files from the current directory.
Done.
When I check the real results of running it.
Code:
ls *log
killo.log  killtemp.log

So what the expletive is wrong with the script?

Carver
 


wizardfromoz

Administrator
Staff member
Gold Supporter
Joined
Apr 30, 2017
Messages
8,957
Reaction score
7,928
Credits
37,761
G'day Carver :)

I am just a novice scripter, but have you tried it with

Code:
*.log

# instead of

*log
?

Other than that, one of our scripting gurus will be along sooner or later :D

Wizard
 

tchakatak

Member
Joined
Nov 14, 2018
Messages
34
Reaction score
36
Credits
0
Hello L Carver,

Remember also, some logs are owned by root, you might have to run your script with root powers.

Take a look at /var/log and list all of the files.

Why not use a logrotate ? Deleting all the logs... its a bit.. hard no?
 

CptCharis

Well-Known Member
Joined
Feb 27, 2018
Messages
563
Reaction score
465
Credits
982
G'day Carver :)

I am just a novice scripter, but have you tried it with

Code:
*.log

# instead of

*log
?

Other than that, one of our scripting gurus will be along sooner or later :D

Wizard
Yeap, Chris I think the same.
 

Members online


Top