Script to purge files in directory

Hi.

I have a surveliance camera and are storing snapshots from it in a folder on my HA server (which is Hass.io on a Rpi). The pictures are uploaded via FTP.

To delete the images in the folder I created a script to run a shell command, but every time when I run the scripts the UI stops responding and I’m getting " 504 Gateway Time-out" from Nginx.

This is what the scripts looks like:

shell_command:
    purge_all_cam_images: rm -r /share/garagecam/5C07A6APAA9E04B

script:
    purge_all_cam_images:
        alias: Delete files
        sequence:
          - service: shell_command.purge_all_cam_images

Any ideas in what I’m doing wrong?
“rm -r” is working if I configure it as a command_line switch.

When the UI stops responding, is there any other ways to reboot the server rather than pulling the plug?