Forum Discussion

JPrice_230829's avatar
JPrice_230829
Icon for Nimbostratus rankNimbostratus
Jan 06, 2016

Execute a shell script prior to full login

Anyone know of a way to initiate a script during ssh login? I have a requirement to provide users with their failed login count, from a remote authentication server, upon successful logon. I have a ldapsearch script that executes once a user logins in but since they just successfully authenticated to the authentication server their badPwdCount is always zero.

 

I've been looking at ssh_config but I can't find a way to make it initiate a shell script.

 

3 Replies

  • You should be able do this the same way you would do on a Linux machine - add your script as a .sh file on /etc/profile.d/ folder.

    For example I created this bash script : myscript.sh in folder /etc/profile.d/ and made it executable using

    chmod +x /etc/profile.d/myscript.sh

    myscript.sh has contents:

    echo "Last Failed login attempt:"
    aureport --login --failed|grep ${USER}|tail -1
    

    now when users ssh to the box they will see their last failed login attempt

    Obviously you can use any other valid commands in your bash script and name it differently. Note that since you are modifying the base operating system config this will not be supported by F5 and can be potentially overwritten during the upgrades.

    Hope this helps,

    Sam

  • Thanks, I've never used the aureport command before. With some help from a coworker this is what I ended up with: startday=$( aureport -au | tail -2 | head -1 | awk '{print $2}' ) starttime=$( aureport -au | tail -2 | head -1 | awk '{print $3}' ) failcount=$(aureport -au --start $startday $starttime | grep $USER | grep no | wc -l) echo "Failed login attempts since your last successful login: ${failcount}"
  • With some help form a coworker this is what I ended up with:

    startdate=$( aureport -au | tail -2 | head -1 | awk '{print $2}' )
    starttime=$( aureport -au | tail -2 | head -1 | awk '{print $3}' )
    failcountt=$(aureport -au --start $startdate $starttime | grep $USER | grep no | wc -l)
    echo "Failed login attempts since your last successful login: ${failcount}"