Skip to content

Instantly share code, notes, and snippets.

@heywoodlh
Last active July 6, 2021 07:51
Show Gist options
  • Save heywoodlh/a0ad5bb81ea9ee896b2a1e5d5f077cfd to your computer and use it in GitHub Desktop.
Save heywoodlh/a0ad5bb81ea9ee896b2a1e5d5f077cfd to your computer and use it in GitHub Desktop.
Post all Lynis warnings and suggestions to slack as a snippet
#!/usr/bin/env bash
if [[ "$1" == '' ]] || [[ "$1" == '--help' ]]
then
echo "$0 [channel id] [slack token]"
exit 0
fi
SLACK_CHANNEL_ID="$1"
SLACK_TOKEN="$2"
SLACK_ICON=':slack:'
MY_HOSTNAME="$(cat /etc/hostname)"
OUTFILE='/tmp/lynis-audit.txt'
lynis audit system --cronjob | grep -Pzo '.*Warnings(.*\n)*' > "$OUTFILE"
LYNIS_WARNINGS="$(cat $OUTFILE)"
curl -F "content=$LYNIS_WARNINGS" -F "initial_comment=lynis report for $MY_HOSTNAME" -F channels="$SLACK_CHANNEL_ID" -F token="$SLACK_TOKEN" https://slack.com/api/files.upload
rm "$OUTFILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment