Skip to content

Instantly share code, notes, and snippets.

@st3b1t
Last active October 4, 2023 10:06
Show Gist options
  • Save st3b1t/e99d7a8f7a55b221a3d69da881318d5b to your computer and use it in GitHub Desktop.
Save st3b1t/e99d7a8f7a55b221a3d69da881318d5b to your computer and use it in GitHub Desktop.
waits for a file to have read group permissions before running a certain command
#!/bin/bash
# Copyright @st3b1t 2023
#
# usage: ./wait-for-chmod.sh /path/to/file/to/check <next-command>
#
# example, check bitcoin cookie file is readable by group:
# ./wait-for-chmod.sh /home/bitcoin/.bitcoin/.cookie <next-command>
#
set -e
perm='-rw-r-----'
file="$1"
shift
cmd="$@"
#set -x
until [[ `stat -c %A $file | cut -c5 ` = 'r' ]]; do
>&2 echo "Group permissions is not readable..."
echo `stat -c %A $file`
sleep 1
done
>&2 echo "Group permissions is readable"
exec $cmd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment