The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

global bash_profile options

Discussion in 'General Discussion' started by easyhttp, Oct 28, 2004.

  1. easyhttp

    easyhttp Active Member

    Joined:
    Dec 25, 2003
    Messages:
    33
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Middle East - Jordan
    Hi
    How to set a global option in Bash_profile and apply it to all users at once?
    example getting Notified when user login via ssh?
     
  2. asmithjr

    asmithjr Well-Known Member

    Joined:
    Jun 13, 2003
    Messages:
    475
    Likes Received:
    1
    Trophy Points:
    18
    .bashrc

    I've not tested this and I got the idea from somewhere else on the forum.

    Assumptions: every login that is allowed shell uses BASH

    Here is a script (.bashrc) that would send an email whenever someone logs in.
    Change email@domain.com to whatever you want.

    Put this file named .bashrc in each HOME directory.

    Code:
    # .bashrc
    
    # User specific aliases and functions
    
    alias rm='rm -i'
    alias cp='cp -i'
    alias mv='mv -i'
    
    # Source global definitions
    if [ -f /etc/bashrc ]; then
            . /etc/bashrc
    fi
    echo 'ALERT - Root Shell Access (ptsamail) on:' `date` `who` | mail -s "Alert: Shell Access from `who | cut -d"(" -f2 | cut -d")" -f1`" email@domain.com
    
    or edit the /etc/bashrc (everyone hits this one)

    put
    Code:
    echo 'ALERT - Root Shell Access (ptsamail) on:' `date` `who` | mail -s "Alert: Shell Access from `who | cut -d"(" -f2 | cut -d")" -f1`" email@domain.com
    
    as the last line if you wish.

    Let me know if it works. I believe the mail command may be blocked in typical servers by users other than root.
     
  3. nickp666

    nickp666 Well-Known Member

    Joined:
    Jan 28, 2005
    Messages:
    770
    Likes Received:
    2
    Trophy Points:
    18
    Location:
    /dev/null
    can you post the full contents of .bash_profile

    (forums foobarred again, should be the last post!)
     
  4. Jeffro

    Jeffro Member

    Joined:
    Jun 21, 2004
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    Code:
    echo 'ALERT - Root Shell Access on:' `date` `who` | mail -s "Alert: Root Access from `who | awk '{print $6}'`" someone@something.com
    When I use this in my /root/.bash_profile, I get a error when I SSH in. It says:

    Code:
    ALERT! You are entering a secured area! Your IP and login information
    have been recorded. System administration has been notified.
    
    This system is restricted to authorized access only. All activities on
    this system are recorded and logged. Unauthorized access will be fully
    investigated and reported to the appropriate law enforcement agencies.
    
    : command not found
    root@master [~]#
    
    : command not found ?

    I am not receiving emails now, and was before I made this change. I needed to update the email address in .bash_profile, and when I changed it, my server stopped sending emails when I log in as root.

    Any ideas?
     
  5. Jeffro

    Jeffro Member

    Joined:
    Jun 21, 2004
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    Code:
    # .bash_profile
    
    # Get the aliases and functions
    if [ -f ~/.bashrc ]; then
    	. ~/.bashrc
    fi
    
    # User specific environment and startup programs
    
    PATH=$PATH:$HOME/bin
    BASH_ENV=$HOME/.bashrc
    USERNAME="root"
    
    export USERNAME BASH_ENV PATH
    
    
    echo 'ALERT - Root Shell Access on:' `date` `who` | mail -s "Alert: Shell Access from `who | cut -d"(" -f2 | cut -d")" -f1`" someone@someone.net
    
    
    
    I changed the email address in the above code.

    Thanks.
     
  6. nickp666

    nickp666 Well-Known Member

    Joined:
    Jan 28, 2005
    Messages:
    770
    Likes Received:
    2
    Trophy Points:
    18
    Location:
    /dev/null
    does it work if you comment out the path line?

    I'm not sure of the character to seperate the path values, may well be the cause (dont forget to take it off of the export line as well)
     
  7. Jeffro

    Jeffro Member

    Joined:
    Jun 21, 2004
    Messages:
    13
    Likes Received:
    0
    Trophy Points:
    1
    Now I am getting two : command not found messages when I SSH in.

    It's wierd, all I did was change the email address a little while ago, and now it's not working. It was working as of this morning.
     
Loading...

Share This Page