How to delete a file from ownCloud server data directory using a bash script (or Linux Terminal) Ubuntu 16.04

Steps to reproduce

  1. Sync a file using the sync folder from desktop/mobile client
  2. In my script, I originally had the command

rm /var/www/owncloud/data/admin/file/

  1. However, I learned not to modify any files behind the back of the owncloud server. When I fail to delete these certain files, it gets the owncloud client into a very odd state where it will continuously fail to sync files that are stuck on the server.

Expected behaviour

Just want to delete certain files automatically via batch script

Actual behaviour

Explained above. File won’t delete. I’ve tried using curl to delete the files, and I would not like to mount the owncloud server data directory elsewhere on the OS – this has given me a multitude of issues before.

Server configuration

Operating system:
Ubuntu 16.04

Web server:

Database:
MySQL

PHP version:
PHP7.0

ownCloud version: (see ownCloud admin page)
v10.2.0

Updated from an older ownCloud or fresh install:
Fresh Install

Where did you install ownCloud from:
Online

Signing status (ownCloud 9.0 and above):

The content of config/config.php:
I’d rather not. data directory is /var/www/owncloud/data



*ATTENTION:* Do not post your config.php file in public as is. Please use one of the above
methods whenever possible. Both, the generated reports from the web-ui and from occ config:list
consistently remove sensitive data. You still may want to review the report before sending.
If done manually then it is critical for your own privacy to dilligently
remove *all* host names, passwords, usernames, salts and other credentials before posting.
You should assume that attackers find such information and will use them against your systems.

List of activated apps:

If you have access to your command line run e.g.:
sudo -u www-data php occ app:list
from within your ownCloud installation folder.

Are you using external storage, if yes which one: local/smb/sftp/…
no

Are you using encryption: yes/no
no

Are you using an external user-backend, if yes which one: LDAP/ActiveDirectory/Webdav/…

LDAP configuration (delete this part if not used)

With access to your command line run e.g.:
sudo -u www-data php occ ldap:show-config
from within your ownCloud installation folder

Without access to your command line download the data/owncloud.db to your local
computer or access your SQL server remotely and run the select query:
SELECT * FROM `oc_appconfig` WHERE `appid` = 'user_ldap';


Eventually replace sensitive data as the name/IP-address of your LDAP server or groups.

Client configuration

Browser:
Chrome

Operating system:
Windows 10

Logs

Web server error log

Insert your webserver log here

ownCloud log (data/owncloud.log)

Insert your ownCloud log here

Browser log

Insert your browser log here, this could for example include:

a) The javascript console log
b) The network log 
c) ...

You could use something like

curl -u user:pass -X DELETE https://localhost/owncloud/remote.php/webdav/sample.txt

Please adjust credentials, server-path and filename according your needs.

3 Likes

I appreciate the response. I tried that exact command yesterday, and the Mail transfer agent was saying I was giving an unsupported input or something similar…uncommented that line back into the script and it works like a charm! Not sure what changed, but thank you nonetheless.

What has it to do with an MTA? Nothing at all.
The code I supplied works as it is.

1 Like

Just because I was running the script as a cron job…but yes, yes it does work. Thanks again

1 Like