Tuesday, December 29, 2020

Script check quemail stuck on server and alert mail to mailadmin for resolve

vim checkquemail.sh

---------------------------------Start---------------------------------------------

#!/bin/bash

#Start check quemail on system

PATHCHECK="/home/user/quemail.txt"

/usr/sbin/postqueue -p |tail -n 1 > $PATHCHECK && /usr/sbin/postqueue -p |grep "^[A-F0-9]" |sort -k5rn -k6n >> $PATHCHECK

#If found quemail stuck on systems and then send mail alert to Systemadmin

#Set the variable which equal to zero

prev_count=0

count=$(grep 'MAILER' $PATHCHECK | wc -l)

#check word 'MAILER' on text file on path $PATHCHECK if more than 0 do next step

if [ "$prev_count" -lt "$count" ] ; then

# Send a mail to given email id when errors found in log

#SUBJECT="WARNING: found $count quemail was stuck on mailgw, pls check now "`date --date='yesterday' '+%b %e'`""

SUBJECT="WARNING: found $count quemail was stuck on mailgw, pls check now."

#This is a temp file, which is created to store the email message.

MESSAGE="/tmp/logs.txt"

FROM="noreply@domain.com"

TO="mailadmin@domain.com"

echo "ATTENTION: found that there are $count mail queues in the system left to be sent for urgent inspection." >> $MESSAGE

echo "Server: `hostname`" >> $MESSAGE

echo "\n" >> $MESSAGE

echo "+------------------------------------------------------------------------------------+" >> $MESSAGE

echo "$count mail queues" >> $MESSAGE

echo "+------------------------------------------------------------------------------------+" >> $MESSAGE

grep -i "`date --date='yesterday' '+%b %e'`" $PATHCHECK | grep 'MAILER' $PATHCHECK >>  $MESSAGE

#list quemail stuck on system

mutt -s "$SUBJECT" -e "my_hdr From: Server Info <noreply@domain.com>" -- "$TO" < $MESSAGE

rm $MESSAGE

fi

---------------------------End Script----------------------------------

Create crontab for run script

---------crontab -e --------

# m h  dom mon dow   command

*/30 * * * * /home/user/./checkquemail.sh

#check every 30 minute

--------


Ref: https://www.2daygeek.com/linux-bash-script-to-monitor-messages-log-warning-error-critical-send-email/


Wednesday, December 2, 2020

Delete old file over 7 day

----------------script--------------------------------------

find /pathfile/* -type f -mtime +7 -exec rm -rf {} \;

--------------------------------------------------------------

Tuesday, June 16, 2020

find and delete file on server linux

how to find and delete file on server linux

#find /data/001/ -name -delete

Ref:
inux-unix-how-to-find-and-remove-files


1. Find Files Using Name in Current Directory

# find . -name tecmint.txt

./tecmint.txt








Wednesday, June 10, 2020

How to install Linux AD controller samba4 on Debian 10


fix problem windows xp not create User Profile on AD server because SAMBA V.4 up not support smbv1 them support smbv2 up

add this to /etc/samba/smb.conf
---------------
[global]
.
.
ntlm auth = ntlmv1-permitted
---------------

systemctl restart samba-ad-dc
systemctl status samba-ad-dc

Add AD user with Profile

samba-tool user add user01 --profile-path=\\\IP\Profiles\\user01

Or change by Active Directory on windows


GPO command
Execute command
gpupdate /force

display execute
gpresult /r


How to setup additional failover replication AD with debian 10.03

1. setup IP and host name
vim /etc/network/interfaces
iface ens192 inet static
address 172.16.x.78/24
gateway 172.16.x.1
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 172.16.x.77 172.16.x.67 172.16.x.68
dns-search ad.domain.com

vim /etc/hosts
127.0.0.1 localhost
172.16.x.77 dc1.ad.domain.com dc1
172.16.x.78 dc2.ad.domai.com dc2

vim /etc/resolv.conf 
search ad.domain.com
nameserver 172.16.x.77
nameserver 172.16.x.67
nameserver 172.16.x.68

Reboot system

ping dc1.ad.domain.com
ping dc2.ad.domain.com

2. install package
apt install samba attr dnsutils net-tools smbclient krb5-user krb5-config winbind libpam-winbind libnss-winbind libpam-krb5

Disable lecacy samba daemons
systemctl stop smbd nmbd winbind
systemctl disable smbd nmbd winbind

Move or delete to default smb.conf file
mv /etc/samba/smb.conf /etc/samba/smb.conf.org

Configure kerberos to use the existing Active Directory. Copy the krb5.conf from Primary domain
scp root@ad.domain.com:/etc/krb5.conf /etc

And get a kerberos ticket for the Active Directory.
kinit administrator
Warning: Your password will expire in 40 days on Mon 01 Feb 2021 02:29:25 PM +07
klist 
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: administrator@AD.DOMAIN.COM

2. run samba-tool command to join the realm using an account with administrative privileges on your domain
#samba-tool domain join ad.domain.com DC -U"administrator"
Finding a writeable DC for domain 'ad.domain.com'
Found DC dc1.ad.domain.com
Password for [WORKGROUP\adminstrator]:

3. Adding configure samba file
vim /etc/samba/smb.conf

       dns forwarder = 172.16.x.67 (IP DNS)
       idmap_ldb:use rfc2307 = yes
.
.
        template shell = /bin/bash
    winbind use default domain = true
    winbind offline logon = false
    winbind nss info = rfc2307
        winbind enum users = yes
        winbind enum groups = yes

4. Enable samba service
        systemctl restart samba-ad-dc.service 
        systemctl status samba-ad-dc.service
        systemctl enable samba-ad-dc.service

5. Check replication. Warning: No NC replicated for Connection! can be ignored
#samba-tool drs showrepl
Warning: No NC replicated for Connection!

6. create link krb5.conf
        mv /etc/krb5.conf /etc/krb5.conf.initial
        ln -s /var/lib/samba/private/krb5.conf /etc/
Test kerberos
# kinit administrator
Password for administrator@AD.DOMAIN.COM:
Warning: Your password will expire in 40 days on Mon 01 Feb 2021 02:29:25 PM +07
# klist 
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: administrator@AD.DOMAIN.COM

7. finish test create user AD dc2.ad.domain.com
root@dc2:~# samba-tool user add 5712016

8. Check user at dc1.ad.domain.com
root@dc1:~# samba-tool user list
Unknown parameter encountered: "profile acls"
Ignoring unknown parameter "profile acls"
uservista
5712016

9. fix join domain debian to debian fail
root@proxy01:~# realm join -U administrator@dc1.ad.domain.com AD.DOMAIN.COM --verbose
 * Resolving: _ldap._tcp.ad.domain.com
 * Resolving: ad.domain.com
 * Performing LDAP DSE lookup on: 172.16.9.77
 * Successfully discovered: ad.domain.com
Password for administrator@ad.domain.com: 
 * Unconditionally checking packages
 * Resolving required packages
 ! PackageKit not available: The name org.freedesktop.PackageKit was not provided by any .service files
 ! Necessary packages are not installed: sssd-tools sssd libnss-sss libpam-sss adcli
realm: Couldn't join realm: Necessary packages are not installed: sssd-tools sssd libnss-sss libpam-sss adcli

msktutil --auto-update --verbose -k /etc/squid/proxy.keytab --computer-name proxy01

fix with install package packagekit
apt install packagekit


Ref.

BASIC USER MANAGEMENT
# sudo su

Display domain users list
 root@smb:~# samba-tool user list

Add a domain user
 root@smb:~# samba-tool user create ubuntu

Delete a domain user
 root@smb:~# samba-tool user delete ubuntu

Reset password for a user
 root@smb:~# samba-tool user setpassword ubuntu

Set expiry for a user
 root@smb:~# samba-tool user setexpiry ubuntu --days=7

Disable/Enable user account
 root@smb:~# samba-tool user disable ubuntu

Display domain groups list
 root@smb:~# samba-tool group list

Display members in a group
 root@smb:~# samba-tool group listmembers "Domain Users"

Add a domain group
 root@smb:~# samba-tool group add ServerWorld

Delete a domain group
 root@smb:~# samba-tool group delete ServerWorld

Add a member from a domain group.
 root@smb:~# samba-tool group addmembers ServerWorld ubuntu

Remove members to group ServerWorld
 root@smb:~# samba-tool group removemembers ServerWorld ubuntu

Change Domain User Password
# sudo smbpasswd -a username
 [sudo] password for admin: 
 New SMB password:
 Retype new SMB password:

Ref:
1. Samba-4-Active-Directory-Domain-Controller-on-Ubuntu-18-04-Server
2. install-samba-4-7-6-ad-dc-ubuntu-18-04-bind-9-11-dns-backend-ad-rfc2307
3. Profile
4. Install AD Controller to windows
5. Restrict website
6. manage-samba4-active-directory-linux-command-line/

Monday, May 11, 2020

Access file windows from Linux

Linux server
List share file on windows
smbclient --user=windows user -L //IP Address windows server
smbclient --user=U001 -L //172.16.0.xx

Access file on windows server
smbclient //IP Address windows server/File share -U windows user
smbclient //172.16.0.xx/Fileshare -U U0001

Thursday, April 23, 2020

install epel-release on centos 8

install epel-release

Turn on EPEL repo on CentOS 8
Make sure EPEL repo enabled and installed. If not, run:
vivek@centos8-box:$ sudo yum -y install epel-release
vivek@centos8-box:$ sudo yum repolist

Ref: how-to-install-htop-on-centos-linux-8

Monday, April 6, 2020

Linux command check IP public when you connect to internet at that location


1. dig +short myip.opendns.com @resolver1.opendns.com
2. dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'"' '{ print $2}'

Ref: debian 10 set up openvpn-server in 5 minutes

Friday, March 13, 2020

ubuntu server 18.04 boot slow more 2 minute

After install ubuntu server 18.04 and found boot more 2 minute and have a error "a start job is running for wait for network to be configured"

How to fix this error check network interface
sudo networkctl
IDX LINK             TYPE               OPERATIONAL SETUP   
  1 lo               loopback           carrier     unmanaged
  2 enp4s5           ether              routable    configured
  3 enp5s0           ether              no-carrier  configuring

sudo networkctl status enp4s5

1. sudo vim /run/systemd/generator/network-online.target.wants/systemd-networkd-wait-online.service

change this line
ExecStart=/lib/systemd/systemd-networkd-wait-online
to
ExecStart=/lib/systemd/systemd-networkd-wait-online --interface=enp4s5 --quiet

------------------edit-----------------------------------

[Service]
Type=oneshot
ExecStart=/lib/systemd/systemd-networkd-wait-online --interface=enp4s5 --quiet
RemainAfterExit=yes
Ô

------------------end------------------------------------

2. reboot

Ref: a-start-job-is-running-for-wait-for-network-to-be-configured-ubuntu-server-17-1

Thursday, March 12, 2020

install and configure x11vnc on ubuntu server 18.04 LTS

sudo apt-get install x11vnc
x11vnc -storepasswd 

Enter VNC password: *********
Verify password: *********  
Write password to /home/rahul/.vnc/passwd?  [y]/n y
Password written to: /home/rahul/.vnc/passwd
sudo x11vnc -auth guess -forever -loop -noxdamage -repeat -rfbauth /home/rahul/.vnc/passwd -rfbport 5900 -shared
script auto start
1. make file x11vnc.service in /etc/systemd/system : sudo mcedit /etc/systemd/system/x11vnc.service (mcedit – my prefered editor , i’m sorry for vi :)))
with text (change RAHUL for you name):
[Unit] Description=x11vnc remote desktop server After=multi-user.target
[Service] Type=simple ExecStart=/usr/bin/x11vnc -auth guess -forever -loop -noxdamage -repeat -rfbauth /home/RAHUL/.vnc/passwd -rfbport 5900 -shared
Restart=on-failure
[Install] WantedBy=multi-user.target
2. sudo systemctl daemon-reload sudo systemctl start x11vnc sudo systemctl status x11vnc
3. if it’s worked sudo systemctl enable x11vnc.service
Ref: setup-x11vnc-server-on-ubuntu-linuxmint

Tuesday, March 10, 2020

install and configure snmp

1. For CentOS 7
install service snmp

yum install net-snmp net-snmp-utils -y

Set configure file /etc/snmp/snmpd.conf
--------------------------------edit------------------------------------------------------------
#       sec.name  source          community
com2sec mynetwork  default       systemsecret

####
# Second, map the security name into a group name:

#       groupName      securityModel securityName
group   notConfigGroup v1           mynetwork
group   notConfigGroup v2c          mynetwork

# Make at least  snmpwalk -v 1 localhost -c public system fast again.
#       name           incl/excl     subtree         mask(optional)
view    systemview    included   .1.3.6.1.2.1.1
view    systemview    included   .1.3.6.1.2.1.25.1.1

####
# Finally, grant the group read-only access to the systemview view.

#       group          context sec.model sec.level prefix read   write  notif
access  notConfigGroup ""      any       noauth    exact  systemview none none
--------------------------------save configure-----------------------------------------------

Enable service
systemctl enable snmpd
systemctl start snmpd
systemctl status snmpd

Check port runing
netstat -tulpn
udp        0      0 0.0.0.0:161             0.0.0.0:*                           21402/snmpd

Test snmpd at local server
snmpwalk -v 1 -c systemsecret -O e 127.0.0.1

Add firewall
firewall-cmd --permanent --add-port=161/udp
firewall-cmd --reload
firewall-cmd --list-all



2. For Debain 9
Install service snmpd

apt install snmpd snmp libsnmp-dev

Edit configure /etc/snmp/snmpd.con
---------------------------------------------------------
AGENT BEHAVIOUR
#
#  Listen for connections from the local system only
agentAddress  udp:127.0.0.1:161,udp:192.168.0.xx:161

ACCESS CONTROL
#
                                                 #  system + hrSystem groups only
view   systemonly  included   .1.3.6.1.2.1.1
view   systemonly  included   .1.3.6.1.2.1.25.1

                                                 #  Full access from the local host
#rocommunity public  localhost
                                                 #  Default access to basic system info
# rocommunity public  default    -V systemonly
 rocommunity serversecret  default    -V systemonly
                                                 #  rocommunity6 is for IPv6
 rocommunity6 public  default   -V systemonly
#rocommunity secret  10.0.0.0/16
                                                 #  Full read-only access for SNMPv3
 rouser   authOnlyUser

SYSTEM INFORMATION
#
#  Note that setting these values here, results in the corresponding MIB objects being 'read-only'
#  See snmpd.conf(5) for more details
sysLocation    Sitting on the Dock of the Bay
sysContact     Me
                                                 # Application + End-to-End layers
sysServices    72
---------------------------------------------------------------------------
Enable service
systemctl enable snmpd
systemctl start snmpd
systemctl status snmpd

Check port runing
netstat -tulpn
udp        0      0 192.168.0.xx:161         0.0.0.0:*                           12142/snmpd         
udp        0      0 127.0.0.1:161           0.0.0.0:*                           12142/snmpd

ss -alnp | grep snmp | grep 161
udp    UNCONN     0      0      192.168.0.xx:161                   *:*                   users:(("snmpd",pid=12142,fd=12))
udp    UNCONN     0      0      127.0.0.1:161                   *:*                   users:(("snmpd",pid=12142,fd=9))

Test snmpd at local server
snmpwalk -v2c -c serversecret localhost

Add firewall
firewall-cmd --permanent --add-port=161/udp
firewall-cmd --reload
firewall-cmd --list-all



Wednesday, January 22, 2020

Configure Master / Slave BIND DNS Server on CentOS 8 / RHEL 8

Configure Master / Slave BIND DNS Server on CentOS 8 / RHEL 8



for check zone file
named-checkzone abc.com /var/named/abc.com.zone
Directory zone = /var/named/

dnstop ens192
dnstop -l 2 ens192
dnstop -l 3 ens192
yum install dnstop

Tuesday, January 7, 2020

How to Add New Disks Using LVM to an Existing Linux System

How to Add New Disks Using LVM to an Existing Linux System


Read on this web site add-new-disks-using-lvm-to-linux