Get the most out of your Centmin Mod LEMP stack
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 Premium Member Premium Member

    4,086
    428
    83
    May 31, 2014
    Ratings:
    +834
    Local Time:
    1:53 PM
    Nginx-1.25.x
    MariaDB 10.3.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

    54,895
    12,240
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,811
    Local Time:
    9:53 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    what are you trying to do ?
     
  3. pamamolf

    pamamolf Premium Member Premium Member

    4,086
    428
    83
    May 31, 2014
    Ratings:
    +834
    Local Time:
    1:53 PM
    Nginx-1.25.x
    MariaDB 10.3.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

    54,895
    12,240
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +18,811
    Local Time:
    9:53 PM
    Nginx 1.27.x
    MariaDB 10.x/11.4+
    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