Zend certified PHP/Magento developer

Bash script behaves differently between local and remote execution

I got the following script to run pre-backup stuff on my server :

#!/bin/bash
dump_name="nextcloud_$(date +%d-%m-%y_%H-%M-%S)_backup.sql"
printf "Enabling maintenance mode... " 
docker exec -u www-data nextcloud_front_1 sh -c "php occ maintenance:mode --on"
printf "nDumping database...n"
docker exec nextcloud_database_1 sh -c 'mysqldump -u root -p$MYSQL_ROOT_PASSWORD nextcloud' | sudo tee "/data/nextcloud/database/dumps/$dump_name" > /dev/null

This works normally when I run it on the server manually via SSH but I’d like to run it remotely :

ssh user@host 'bash -s' < script.sh

But then I get the following output among printf’s:

" option does not exist.

maintenance:mode [--on] [--off]

Caused by this line

docker exec -u www-data nextcloud_front_1 sh -c "php occ maintenance:mode --on"

I tried the following :

docker exec -u www-data nextcloud_front_1 sh -c "php occ maintenance:mode --on"
docker exec -u www-data nextcloud_front_1 sh -c 'php occ maintenance:mode --on'
docker exec -u www-data nextcloud_front_1 php occ maintenance:mode --on

Also, running :

docker exec -u www-data nextcloud_front_1 echo 'php occ maintenance:mode --on'

Outputs as expected

php occ maintenance:mode --on

So I don’t really have any idea where the error comes from…