Skip to content

Instantly share code, notes, and snippets.

@potaracom
Created February 21, 2021 03:38
Show Gist options
  • Save potaracom/dac2cedf29c268afaa34933a12697aec to your computer and use it in GitHub Desktop.
Save potaracom/dac2cedf29c268afaa34933a12697aec to your computer and use it in GitHub Desktop.
CloudWatch Logsのtail -f
#!/usr/bin/bash
prompt="ロググループ名を選択してください:"
options=$(aws logs describe-log-groups | jq -r ".logGroups[] | select( .logGroupName | contains(\"$1\")) | .logGroupName")
if [[ $options == "" ]]; then
echo "ロググループが存在しませんでした。"
exit 0
fi
count=$(echo "$options" | wc -l)
if (( $count == 1 )); then
echo aws logs tail --follow $options
aws logs tail --follow $options
exit 0
fi
PS3="$prompt "
select option in ${options[@]} "Quit" ; do
if [[ $option == "Quit" ]]; then
echo "終了します。"
exit 0
elif [[ $option == "" ]]; then
echo "選択肢ではない値が入力されました。再度入力してください。"
else
break
fi
done
echo "log($option)のウォッチを開始します。"
aws logs tail --follow $option
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment