This is in reference to this question.
I wanted to log everytime someone logged in via ansible.
I put my script in ~/.bash_profile
file. Here is the script,
#!/bin/bash
now=$(date +"%T")
echo "$USER logged in at: $now" >> /home/alphauser/ssh-entries.log
I put this at the end of ~/.bash_profile
,
bash ~/ssh-login-entry.sh
However, ansible uses the non-interactive shell, so my script was not executed when I logged in via ansible as ~/.bash_profile
is executed only when a new interactive shell is started.
Then I pasted this at the end of .bashrc
file, but still it did not work.
How can I log entries when someone logs in via non-interactive shell ? I mean where should I place this script so that it should be executed everytime someone logs in via ansible ?
I hope the question is clear.
~/.bashrc
for non-login shells.bash_profile
, then I suggest you at least copy the code from.profile
into it. But I don't know if that will prevent all possible issues...auth.log
file (in/var/log
) not useful for this?.bash_profile
, it's just not relevant here because the OP is running a non-interactive shell. Basically, if.bash_profile
exists, then.profile
is ignored bybash
. But that's no reason not to use it. Especially if you want to have separate settings for different shells (~/.bash_profile
is only read bybash
while~/.profile
is read by most or all login shells).