• About

http://blog.fakrul.com

http://blog.fakrul.com

Tag Archives: BASH Script

3 easy steps to create aliases file (all the users of mail server)

23 Sunday Jun 2013

Posted by Fakrul Alam in Uncategorized

≈ Leave a comment

Tags

aliases, BASH, BASH Script, postfix

Step 1: Get all the user name from /etc/passwd file

root@access /h/fakrul# awk -F’:’ ‘{ print $1 }’ /etc/passwd > userlist.txt

Step 2: Add , at end of each line

root@access /h/fakrul# sed -e ‘s/$/,/’ userlist > userlist2.txt

Step 3: Remove all the line break and replace them with space

root@access /h/fakrul# sed ‘:a;N;$!ba;s/n/ /g’ userlist2.txt > userlist3.txt

Now create the desire aliases file from this txt file.

IP address delegated by APNIC (Convert it to CIDR Format)

06 Monday May 2013

Posted by Fakrul Alam in Uncategorized

≈ Leave a comment

Tags

APNIC, BASH Script, CIDR

1. Go to ftp://ftp.apnic.net/pub/stats/apnic/

Download the latest delegated-apnic* file. This file contnet all the IP address and ASN delegated by APNIC to it’s region. Open the file and remove the comments and ASN part.

2. Get those IP which are allocated to BD.

# more delegated-apnic-20130506 | grep BD > bdip.txt

Now you have bdip.txt file having following content:

apnic|BD|ipv4|27.0.96.0|8192|20110302|allocated
apnic|BD|ipv4|27.131.12.0|1024|20100421|allocated
apnic|BD|ipv4|27.147.128.0|32768|20100331|allocated
apnic|BD|ipv4|42.0.4.0|1024|20110317|allocated
apnic|BD|ipv4|42.99.116.0|1024|20110322|allocated
apnic|BD|ipv4|49.0.32.0|8192|20101027|allocated
apnic|BD|ipv4|58.65.224.0|2048|20060607|allocated
apnic|BD|ipv4|58.97.128.0|32768|20110107|allocated
apnic|BD|ipv4|58.145.184.0|2048|20060615|allocated
apnic|BD|ipv4|58.147.168.0|2048|20060613|allocated

3. Filed no 4 has the IP address and field no 5 has the no of host. Fetch the IP address and no of host and replace the | by /.

# awk -F”|” ‘{ print $4″/”$5}’ bdip.txt > bdip2.txt

4. File bdip2.txt look like:

27.0.96.0/8192
27.131.12.0/1024
27.147.128.0/32768
42.0.4.0/1024
42.99.116.0/1024
49.0.32.0/8192
58.65.224.0/2048
58.97.128.0/32768
58.145.184.0/2048
58.147.168.0/2048

5. Now we have to replace the no of host part to CIDR subnet mask. No of host represent following CIDR:

No of Host->CIDR
256->24
512->23
1024->22
2048->21
4096->20
8192->19
16384->18
32768->17
65536->16
131072->15

6. You can manually change this No of Host to CIDR using bash find replace command:

# bdip2.txt
# :%s/256/24

What it does is replace all 256 by 24. You can do the same for other subnet.

If you are an advance shell script coder, you can write a shell script and replace at once. I am not that good in bash, so I do it manually.

Now you can use it for filtering based on IP/SUBNET. I basically use it for zone based DNS configuration.

If you need to add ; at the end of each line, do the following:

# sed ‘s/$/;/’ bdip2.txt

Create user & Change password by BASH Script

09 Monday Oct 2006

Posted by Fakrul Alam in Uncategorized

≈ Leave a comment

Tags

BASH, BASH Script, Change Password, Shell Script, Tutorial

This two scripts are very important for the system admin who regularly works with mail server and some how forget to backup their system username and password!!!. Let’s say some how we lost the server username and password of the mail server. In this case the admin has to manually create all the users and than change the password for all the user. Tedious job :-). Let’s make our life easier.

First create a file which contains all the user name. Something like this:



nurealam
nayeem
mrahman
farid
rubi
sankar




Save the file as userlist.txt

Now create the following bash file:



#!/bin/sh
for i in `more userlist.txt `
do
echo $i
adduser $i
done

Save the file and exit. chmod 755 userlist.txt. Now run the file by ./userlist.txt. This will add all the user to the system.

Now we have to change the password. Lets say we want username123 as password. So for user nayeem the password will be nayeem123, rubi123 for user rubi and so on.


Create another bash file as following:



#!/bin/sh
for i in `more userlist.txt `
do
echo $i
echo $i”123” | passwd —stdin “$i”
echo; echo “User $username’s password changed!”
done

Run the file. All the password are changed 🙂

Social

  • View rapappu’s profile on Twitter
  • View fakrulalam’s profile on LinkedIn
  • View fakrul’s profile on GitHub
  • View FakrulAlamPappu’s profile on Google+
  • View fakrulalam’s profile on Flickr

Twitter Updates

  • 1976 forming the modern-day #Vietnam 1971 #Bangladesh independence When we could see something like this happening… twitter.com/i/web/status/1… 4 days ago
  • The beauty is here #Keychron #K2 Mechanical Keyboard https://t.co/j5OVbpmvKi 5 days ago
  • blog.fitbit.com/2021-update/?u… #fitbit + #google https://t.co/X2g7HpIMvI 1 week ago
  • #DevNet Class of 2020. View my verified achievement from @learningatcisco. youracclaim.com/badges/bf864fa… 1 month ago
  • #pythonprogramminglanguage #python #pyenv towardsdatascience.com/how-to-set-up-… 1 month ago
  • wsj.com/articles/u-s-c… 1 month ago
  • bleepingcomputer.com/news/security/… 1 month ago
  • RT @GinNTTnet: Carriers, Internet-centric businesses and enterprises can prepare themselves to fight against #DDoS attacks. Download this w… 2 months ago
  • #LoRaWAN GPS payload is coming nicely to #AzureIotHub @GlobalNTT @CiscoDevNet #ntthackfest2020 https://t.co/VqYi7dMBoq 2 months ago
  • RT @GinNTTnet: Paolo Lucente @Paolo_Lucente from the #globalipnetwork division at @GlobalNTT will present this Monday Oct 12 at the Next Ho… 3 months ago
  • RT @bdNetOpGroup: Make sure we always "Learning from failures". Wanna know more? Please join bdnog.org/bdnog12/index.…. Because our very own… 3 months ago
  • RT @bdNetOpGroup: #bdNOG12 Panel Discussion: "Social CDN Business : Paid or Free". Make sure you register and join bdnog.org/bdnog12/index.…… 3 months ago
  • RT @teamcymru: #DDoS Attacks Hit 1 Tbps in #2020 #infosec bit.ly/2ZLmAlK https://t.co/Ezx3s5xVcw 4 months ago
  • github.blog/2020-09-10-ann… #msteams #github 4 months ago
  • I just backed Keychron K3 -Ultra-slim Compact Wireless Mechanical Keyboard on @Kickstarter kickstarter.com/projects/keytr… 4 months ago
Follow @rapappu

Tags

antismap antivirus automation Azure bangladesh BASH BASH Script BDCERT bgp bind ccsp centos CentOS mirror CERT CISA cisco Cyber Security ddos dhaka dhakacom DNS DNSSEC GSM intrusion detectoin system Intrusion prevention system ips IPv6 ISACA junos linux Looking Glass lxc lxc profile lxd mailqueue mailscanner Mail Server mailwatch Meraki mikrotik monitor mpls MPLS L3 VPN mysql My Work network network management nginx NSD observium OpenVPN perl PHP ping postfix Proxy PTA python RANCID Reading RPKI Shell Script sms sms server SNMP SSH Tutorial ubuntu Ubuntu Mirror Server Virtual Box vispan vmware websvn Youtube hack খামাখা

Blog at WordPress.com.