Join the community today
Become a Member

Sysadmin Centos 6 command doesn't report the same on Centos 7

Discussion in 'System Administration' started by pamamolf, Nov 15, 2016.

  1. pamamolf

    pamamolf Well-Known Member

    2,498
    229
    63
    May 31, 2014
    Ratings:
    +390
    Local Time:
    4:13 PM
    Nginx-1.13.x
    MariaDB 10.1.x
    Hello

    I am testing a command on Centos 6 :

    Code:
    who | cut -d'(' -f2 | cut -d')' -f1
    and it works great with the output:

    Code:
    blabladsl-1271874.home.domain.com
    but the same command on Centos 7 is returning my ip only :(

    Any ideas?
     
  2. eva2000

    eva2000 Administrator Staff Member

    28,972
    6,575
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,759
    Local Time:
    11:13 PM
    Nginx 1.13.x
    MariaDB 5.5
    what are you trying to do ?
     
  3. pamamolf

    pamamolf Well-Known Member

    2,498
    229
    63
    May 31, 2014
    Ratings:
    +390
    Local Time:
    4:13 PM
    Nginx-1.13.x
    MariaDB 10.1.x
    I try to set email alert on ssh login but i need to have the ip and nameserver so i will know the country without doing manually a trace for it....
     
  4. eva2000

    eva2000 Administrator Staff Member

    28,972
    6,575
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,759
    Local Time:
    11:13 PM
    Nginx 1.13.x
    MariaDB 5.5
    Easier to do something like this
    Code (Text):
    SSH_ALERTEMAIL='your@emailaddr.com'
    SSH_ALERTIP=$(echo $SSH_CLIENT | awk '{print $1}')
    SSH_ALERTGEO=$(curl -sL ipinfo.io/$SSH_ALERTIP/geo | sed -e 's|[{}]||' -e 's/\(^"\|"\)//g' -e 's|,||')
    echo -e "ALERT: $(whoami) Shell Access $(hostname): $(date)\n$SSH_ALERTGEO" | mail -s "Alert: $(whoami) Shell Access $(hostname) from $SSH_ALERTIP" $SSH_ALERTEMAIL
    

    sample output
    Code (Text):
    ALERT: root Shell Access host.domain.com: Tue Nov 15 16:31:27 UTC 2016
    
      ip: 111.222.222.222
      city: Sydney
      region: New South Wales
      country: AU
      loc: -33.9032150.9677,
      postal: 2012


    posted a thread to Centmin Mod Insights forum at SSH Login Email Alerts Centmin Mod Style | Centmin Mod Community
     
    Last edited: Nov 16, 2016
    • Like Like x 2