My Problem is that my script dont send me the right variables to my Mattermost Channel. I will that my script send when a user login with ssh to my server , with name,ip,ect. And when the login failed send to another channel with information.
i have read many examples and tried. i can send a Text Message to the Channel when a user is login with ssh, but the Information is not included. I tried mattersend instead of curl.
#!/bin/bash
#Variable
USER="User: $PAM_USER"
REMOTE="Remote host: $PAM_RHOST"
SERVICE="Service: $PAM_SERVICE"
TTY="TTY: $PAM_TTY"
DATE="Date: `date`"
SERVER="Server: `uname -a`"
LOGINMESSAGE="$PAM_SERVICE login on `hostname -s` for account $PAM_USER"
if [ "$PAM_TYPE" = "open_session" ]
then
# dont function
curl -i -X POST -d 'payload={"text": "${PAM_RHOST}" , "username":"ssh", "channel":"monitoring"}' \ https://domain/hooks/xxx
# function
curl -i -X POST -d 'payload={"text": "Hello, world!", "username":"sshbot", "channel":"monitoring"}' \ https://domain/hooks/xxx
fi
exit 0
The script is started as optional in the pam.d config
I expected the variables to be transferred when logging in successfully.