Skip to content

Instantly share code, notes, and snippets.

@cronfy
Last active June 2, 2020 07:52
Show Gist options
  • Save cronfy/713b3b9e5e32cd7259763bd65b889aa1 to your computer and use it in GitHub Desktop.
Save cronfy/713b3b9e5e32cd7259763bd65b889aa1 to your computer and use it in GitHub Desktop.
Creates lines for crontab for bitrix
#!/usr/bin/env bash
BITRIX_WWW_DIR="$1"
[ -z "$BITRIX_WWW_DIR" ] && BITRIX_WWW_DIR="."
[ ! -d "$BITRIX_WWW_DIR" ] || [ ! -d "$BITRIX_WWW_DIR/bitrix" ] || [ ! -f "$BITRIX_WWW_DIR/index.php" ] || [ ! -d "$BITRIX_WWW_DIR/bitrix/php_interface" ] && {
if [ "$BITRIX_WWW_DIR" = "." ] ; then
echo " !! Bitrix not found in current directory." >&2
else
echo " !! Bitrix not found in $BITRIX_WWW_DIR" >&2
fi
exit 1
}
BITRIX_WWW_DIR="`realpath "$BITRIX_WWW_DIR"`"
declare -a php_executables
php_executables+=(`which php`)
[ -x "/opt/php71/bin/php" ] && {
php_executables+=(/opt/php71/bin/php)
}
[ -x "/opt/php74/bin/php" ] && {
php_executables+=(/opt/php74/bin/php)
}
echo "${php_executables[@]}"
if [ "${#php_executables[@]}" -gt "1" ] ; then
php=""
while [ -z "$php" ] ; do
echo
for index in "${!php_executables[@]}" ; do
let i=($index + 1)
echo "$i. ${php_executables[$index]} `php -r 'echo phpversion();'`"
done
echo
read -p "Select php: " selection
echo "$selection" | head -n 1 | grep -qE "^[0-9]$" || continue
let s=($selection - 1)
php="${php_executables[$s]}"
[ -z "$php" ] && continue
echo
echo "This php will be used: $php"
echo
read -p "Correct (y/n)? " answer
[ "$answer" != "y" ] && php=""
done
else
php=${php_executables[0]}
fi
[ -z "$php" ] || [ ! -x "$php" ] && {
echo "Failed to select php" >&2
exit 1
}
echo -e "\n\n\n\n\n"
echo "Use these lines for crontab:"
echo "----------------------------"
echo
echo "
SITE_WWW=\"$BITRIX_WWW_DIR\"
* * * * * test -f \$SITE_WWW/bitrix/modules/main/tools/cron_events.php && { $php -f \$SITE_WWW/bitrix/modules/main/tools/cron_events.php; } >/dev/null 2>&1
"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment