stop docker desktop mac before backup process

Hi there,

I’ve written a shell script, which stops my docker desktop containers on my mac, so I can execute it via crontab before my automatic backups run via carbon copy cloner.

I can execute the shell script via terminal without any problems.

But if I create a cronjob it doesnt execute this specific docker command. It skips this command but runs other commands without any problems.

Can you please help me with this? Or maybe you can suggest any other way to backup my docker volumes ?

I already gave cron permissions for full drive access.

Thx!

Script looks like this:

#!/bin/sh
sudo -u `stat -f %Su /dev/console` docker stop $(Docker ps -a -q)

crontab looks like this:

00 16 * * * cd /Users/tmryvz/Documents/shell_scripts/ && ./docker-stop.sh

Can anyone help pls?


I formatted your post so the backtick is visible. Please, format your posts next time according to the following guide: How to format your forum posts
In short: please, use </> button to share codes, terminal outputs, error messages or anything that can contain special characters which would be interpreted by the MarkDown filter. Use the preview feature to make sure your text is formatted as you would expect it and check your post after you have sent it so you can still fix it.

Example code block:

```
services:
  service1:
    image: image1
```

Do you have cronjob logs? Have you tried to debug what part can run and what not or what is the output of

stat -f %Su /dev/console

When running from a cronjob? I never tried cronjobs on Mac.

What I know is that when I SSH into my Mac, I need to unlock my keychain to use docker commands. Could it be required when you run something from a cronjob as a specific user? This is my script

#!/usr/bin/env bash

# Used when running Docker Desktop containers from a remote machine through SSH.

security -v unlock-keychain ~/Library/Keychains/login.keychain-db

But it requires typing my password as well.