crontab bash tests

Oliver Grawert ogra at ubuntu.com
Mon Sep 25 09:54:28 UTC 2023


hi,
Am Sonntag, dem 24.09.2023 um 18:44 +0200 schrieb lejeczek via ubuntu-
users:
>  Hi guys.
>  
>  I have this 
>  
>  */1 * * * * { [[ $(/usr/bin/sudo -u postgres /usr/bin/psql --quiet -
> -port=5433 -x -c 'select state from pg_stat_replication;' | grep
> streaming > /dev/null)$? -eq 0 ]] && /usr/bin/touch /tmp/pgSQL-
> 5433.isMaster || rm -f /tmp/pgSQL-5433.isMaster; }
>  

the [[ ]] notation is a "bashism", ubuntu defaults to POSIX shell for
/bin/sh (i.e. for all non-interactive scripts) which in turn is then
used by cron ... 

fix the broken notation (just [[ to [ and equivalently ]] to ] ) and it
should work as expected ... 

or if you insist using the bashism you can also run the cron command
through /bin/bash -c (which likely requires more extensve quoting
though).

ciao
	oli
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
URL: <https://lists.ubuntu.com/archives/ubuntu-users/attachments/20230925/5140228c/attachment.sig>


More information about the ubuntu-users mailing list