executeCommandLine strange results with rm

Openhab 2.5 on Raspberry PI 4

I have a rules that execute on the command line, using executeCommandLine.

I have set sudo permissions for the functions I’m running, and they have all been working. However, I am having some trouble with the rm command to remove files from a folder.

I want to remove all files in the folder /var/lib/openhab2/backups.
Via a SSH session, using "sudo rm /var/lib/openhab2/backups/* all works as expected
But when I run this via a rule, I get an error in the logs saying the No such file or directory.

I have tried a few versions….

 executeCommandLine("sudo rm /var/lib/openhab2/backups/*",500)
 executeCommandLine("sudo@@rm@@/var/lib/openhab2/backups/*",500)

But I always get the same error

2020-03-21 17:45:43.530 [DEBUG] [lipse.smarthome.io.net.exec.ExecUtil] - executed commandLine 'sudo rm /var/lib/openhab2/backups/*'
2020-03-21 17:45:43.684 [DEBUG] [lipse.smarthome.io.net.exec.ExecUtil] - exit code '1', result 'rm: cannot remove '/var/lib/openhab2/backups/*': No such file or directory'

If I specify an exact filename then it will run and remove the file as expected, so the issue looks to be with the way it treats the [*] wild card.

Any ideas?
Thanks

I think there are clues here


but most of the offerd solutions won’t apply.

Because executeCommandLine is running a shell, /var/lib/openhab2/backups/* is being treated as a literal i.e. looking for a file called * , not treating it as wildcard.

Thanks for that. I’ve ended up creating it as a simple shell script and then running that from the rule.