server icon indicating copy to clipboard operation
server copied to clipboard

`occ` output not quiet when it should be, exit code not proper

Open tgoeg opened this issue 3 years ago • 14 comments

Steps to reproduce

  1. occ files:scan -- nonexistantuser
{"reqId":"gF4yvg4t66k03R7DWvY4","level":1,"time":"2021-05-19T09:45:18+00:00","remoteAddr":"","user":"--","app":"admin_audit","method":"","url":"--","message":"Console command executed: files:scan -- nonexistant","userAgent":"--","version":"19.0.8.1"}
Unknown user 1 nonexistant
+---------+-------+--------------+
| Folders | Files | Elapsed time |
+---------+-------+--------------+
| 0       | 0     | 00:00:00     |
+---------+-------+--------------+
$ echo $?
0
  1. occ files:scan -q -- nonexistantuser
{"reqId":"cP30drfWr696XfVOnNs1","level":1,"time":"2021-05-19T09:47:12+00:00","remoteAddr":"","user":"--","app":"admin_audit","method":"","url":"--","message":"Console command executed: files:scan -q -- nonexistantuser","userAgent":"--","version":"19.0.8.1"}
  1. occ files:scan -q -- existinguser
{"reqId":"cP30drfWr696XfVOnNs1","level":1,"time":"2021-05-19T09:47:12+00:00","remoteAddr":"","user":"--","app":"admin_audit","method":"","url":"--","message":"Console command executed: files:scan -q -- existinguser","userAgent":"--","version":"19.0.8.1"}

Expected behaviour

  1. Less output (see 3. below), but most of all, an exit code indicating an error has occurred.
  2. I said quiet! Still I get (irrelevant, to me) output but the one that should actually be issued (there has been an error!) gets suppressed!
  3. The logfile details in JSON should generally not be shown. Silence is golden. Using this (and most likely other occ commands as well, this is a more general issue!) in cron jobs/scripts always leads to notifications. If there is no error, do not output anything. Especially not when asked to be quiet. There are verbose flags. If using them, output can be generated. Only output error messages to stderr (or maybe verbose messages, if asked to). Yes, I can redirect stderr to /dev/null but that's not sensible. I'd like to get notified if an actual error occurs!

Server configuration

Nextcloud version: 19.0.8.1

The rest is irrelevant.

tgoeg avatar May 19 '21 10:05 tgoeg

This is somewhat related to #24300 as this also affects scriptability.

tgoeg avatar May 19 '21 10:05 tgoeg

Also related to #23596 as this is another case of not correctly separating stdout from stderr.

tgoeg avatar May 19 '21 10:05 tgoeg

I've tested 2 and 3, no output in both cases. For 1, i don't get any JSON return.

php occ files:scan -- user
Starting scan for user 1 out of 1 (user)
+---------+-------+--------------+
| Folders | Files | Elapsed time |
+---------+-------+--------------+
| 11      | 25    | 00:00:00     |
+---------+-------+--------------+

Nextcloud 21.0.2.

solracsf avatar May 28 '21 13:05 solracsf

Alright, reading my output again this might be caused by "app":"admin_audit" Still, occ should have control over what gets sent to the console and what not, right?

tgoeg avatar May 31 '21 07:05 tgoeg

Is this Issue still valid in NC21.0.3? If not, please close this issue. Thanks! :)

szaimen avatar Jul 06 '21 16:07 szaimen

This issue has been automatically marked as stale because it has not had recent activity and seems to be missing some essential information. It will be closed if no further activity occurs. Thank you for your contributions.

ghost avatar Aug 05 '21 17:08 ghost

Sorry for the delay - had to update OS to be able to update NC as well. Yes, I can confirm it is the same on NC 21.0.3, still wrong Unknown user 1 nonexistantuser output and still wrong return code. I don't seem to get the admin_audit stanzas anymore, regardless of using -q or not.

tgoeg avatar Aug 11 '21 22:08 tgoeg

Also: #19974

uusijani avatar Jan 16 '22 18:01 uusijani

For those needing a workaround in the meantime:

${ncbasedir}/occ files:scan -- "$ncshareuser" 2>&1 | egrep -v '("app":"admin_audit")|(^[+|])|Starting\ scan' && die "Error scanning files with nextcloud occ"

Note the deliberate logic inversion && die because grep will exit unsuccessfully only if it lets strings through (=did not match all). Use case: Some application generates data that shall be put into a shared dir. For NC to pick up the changes, occ files:scan needs to be invoked. I want to make sure the step went OK.

tgoeg avatar Feb 15 '22 12:02 tgoeg

Hi, please update to 24.0.9 or better 25.0.3 and report back if it fixes the issue. Thank you!

My goal is to add a label like e.g. 25-feedback to this ticket of an up-to-date major Nextcloud version where the bug could be reproduced. However this is not going to work without your help. So thanks for all your effort!

If you don't manage to reproduce the issue in time and the issue gets closed but you can reproduce the issue afterwards, feel free to create a new bug report with up-to-date information by following this link: https://github.com/nextcloud/server/issues/new?assignees=&labels=bug%2C0.+Needs+triage&template=BUG_REPORT.yml&title=%5BBug%5D%3A+

szaimen avatar Jan 23 '23 11:01 szaimen

The exit code issue is still there:

# sudo -u www-data /usr/bin/php /var/www/nextcloud/occ --version
Nextcloud 25.0.3
# sudo -u www-data /usr/bin/php /var/www/nextcloud/occ files:scan -- nonexistantuser
Unknown user 1 nonexistantuser
+---------+-------+--------------+
| Folders | Files | Elapsed time |
+---------+-------+--------------+
| 0       | 0     | 00:00:00     |
+---------+-------+--------------+
# echo $?
0

uusijani avatar Jan 25 '23 12:01 uusijani

which nc version did you test?

szaimen avatar Jan 25 '23 12:01 szaimen

25.0.3 (as indicated by output from occ --version above).

uusijani avatar Jan 25 '23 13:01 uusijani

I can reproduce on 25.0.6.

sblondon avatar Jun 19 '23 14:06 sblondon