server
server copied to clipboard
`occ` output not quiet when it should be, exit code not proper
Steps to reproduce
-
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
-
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"}
-
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
- Less output (see 3. below), but most of all, an exit code indicating an error has occurred.
- 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!
- 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.
This is somewhat related to #24300 as this also affects scriptability.
Also related to #23596 as this is another case of not correctly separating stdout from stderr.
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.
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?
Is this Issue still valid in NC21.0.3? If not, please close this issue. Thanks! :)
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.
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.
Also: #19974
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.
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+
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
which nc version did you test?
25.0.3 (as indicated by output from occ --version
above).
I can reproduce on 25.0.6.