Showing posts with label Debian. Show all posts
Showing posts with label Debian. Show all posts

Saturday, January 20, 2018

Setup mail forwarding in postfix on Debian or Ubuntu

Install Postfix
$ sudo apt-get install postfix
After Install check postfix status
$ sudo service postfix status

Further check that postfix is running a server on port 25 with the netstat command
$ sudo netstat -ltnp | grep 25
Output : 
tcp        0      0 127.0.0.1:25      0.0.0.0:*    LISTEN      1926/master     
tcp6       0      0 ::1:25            :::*         LISTEN      1926/master
Verify DNS settings of domain
$ sudo dig example.com mx

Configure postfix to forward mails

Check the path of config folder using  postconf command
$ postconf | grep config_directory
config_directory = /etc/postfix

Edit the main.cf file and add following lines at end if  it

virtual_alias_domains = mydomain.com anotherdomain.com
virtual_alias_maps = hash:/etc/postfix/virtual

Now Create /etc/postfix/virtual file and add emails to forwad along with destination mails like:

myemail@domain.com   destination@gmail.com
othermail@domain.com otherdes@yahoo.com

First mail  address receive emails, and the second address would forward the emails.

For all forward emails use following lines

@mydomian.com  des@gmail.com 

After this save file and close it and run following commands

$ postmap /etc/postfix/virtual
$ sudo service postfix reload.

Now try to send an email from somewhere to the address on yourdomain and the same mail forwarded to other account.

Thursday, July 9, 2015

Create list of all installed packages by date in Ubuntu or Debian

#!/bin/bash
#creates file with a list of all packages installed by date
#append all info from archived logs

i=2
mycount=$(ls -l /var/log/dpkg.log.*.gz | wc -l)
nlogs=$(( $mycount + 1 ))

while [ $i -le $nlogs ]
do
if [ -e /var/log/dpkg.log.$i.gz ]; then
zcat /var/log/dpkg.log.$i.gz | grep "\ install\ " >> $HOME/packagetmp.txt
fi
i=$(( $i+1 ))
done

#Next append all info from unarchived logs
i=1
nulogs=$(ls -l /var/log/dpkg.log.* | wc -l)
nulogs=$(( $nulogs - $nlogs + 1 ))
while [ $i -le $nulogs ]
do
if [ -e /var/log/dpkg.log.$i ]; then
cat /var/log/dpkg.log.$i | grep "\ install\ " >> $HOME/packagetmp.txt
fi
i=$(( $i+1 ))
done

#Now append current log
cat /var/log/dpkg.log | grep "\ install\ " >> $HOME/packagetmp.txt
#sort file data by date

sort -n $HOME/pkgtmp.txt > $HOME/packageinstalls.txt
rm $HOME/packagetmp.txt
exit 0