Moving emails to new host with imapsync

More info about imapsync here

Install imapsync

CentOS 7, Works on cPanel servers too

yum install epel-release && yum install imapsync

Once installed check and make sure it works.

imapsync --version

If it gives you the version number you should be good to go.

Move email account

imapsync --host1 mail.emaildomain.com --user1 username@emaildomain.com --password1  "password1" --host2 mail.exampledomain.com --user2 username@movetodomain.com --password2  "password2"

Example :

imapsync --host1 mail.myemail.com --user1 bob@myemail.com --password1  "password1" --host2 mail.incredigeek.com --user2 bob@incredigeek.com --password2  "password2"

Moving Multiple accounts

Best way to move multiple accounts is to use a script and and a list that contains all the usernames and passwords to the accounts you want to move.

example scripts can be found on the imapsync website here is a script example and here is the example file.txt

Example script.

#!/bin/sh
#
# $Id: sync_loop_unix.sh,v 1.6 2015/11/04 18:23:04 gilles Exp gilles $

# Example for imapsync massive migration on Unix systems.
# See also http://imapsync.lamiral.info/FAQ.d/FAQ.Massive.txt
#
# Data is supposed to be in file.txt in the following format:
# host001_1;user001_1;password001_1;host001_2;user001_2;password001_2;
# ...
# Separator is character semi-colon ";" it can be changed by any character changing IFS=';' 
# in the while loop below.
# # Each line contains 6 columns, columns are parameter values for 
# --host1 --user1 --password1 --host2 --user2 --password2
# and a trailing empty fake column to avaid CR LF part going 
# in the 6th parameter password2. Don't forget the last semicolon.
#
# You can add extra options after the variable "$@" 
# Use character backslash \ at the end of each suplementary line, except for the last one.
# You can also pass extra options via the parameters of this script since
# they will be in "$@"

# The credentials filename "file.txt" used for the loop can be renamed 
# by changing "file.txt" below.


echo Looping on account credentials found in file.txt
echo

{ while IFS=';' read  h1 u1 p1 h2 u2 p2 fake
    do 
        { echo "$h1" | egrep "^#" ; } > /dev/null && continue # this skip commented lines in file.txt
        echo "==== Starting imapsync from host1 $h1 user1 $u1 to host2 $h2 user2 $u2 ===="
        imapsync --host1 "$h1" --user1 "$u1" --password1 "$p1" \
                 --host2 "$h2" --user2 "$u2" --password2 "$p2" \
                 "$@"  
        echo "==== Ended imapsync from host1 $h1 user1 $u1 to host2 $h2 user2 $u2 ===="
        echo
    done 
} < file.txt

Example list of accounts to

mail.maildomain.com;user1@incredigeek.com;password1;mail.incredigeek.com;user2@incredigeek.com;password2;

 

How to use,

You can run these command from a Linux computer

Download script

wget www.incredigeek.com/home/downloads/imapsync/imapsync_loop.sh

Make the script executable

chmod +x imapsync_loop.sh

Create a text file named “imapsync_list.txt”

This file will contain the mail server to transfer from, username, and password, and then the mail server to transfer to, username and password.  Add one line per account.

Example:

mail.servertotransferfrom.com;Username1;Password1;mail.servertomoveto.com;Username2;Password2;
mail.servertotransferfrom.com;testuser;123456;mail.servertomoveto.com;bob;123456;

Execute the script to start moving mail

./imapsync_loop.sh

Troubleshooting

In the username you may need to use the username@domainname.tld, so if the username is bob, and the mail domain is incredigeek.com, use bob@incredigeek.com for the username in the imapsync_list.txt.

Ubuntu 16.04 Login Screen Issues

This post is not meant to be a how to, but rather a compilation commands that could be helpful in trying to fix issues with the login screen after an upgrade.

These commands should be executed from a prompt, you can get to one using the ctrl+alt+f1 (you can replace f1 with any of the function keys from 1-7), or you can boot up from recovery, or you could mount the drive and chroot into it.

Reinstall Desktop and Login Manager

sudo apt-get install --reinstall lightdm ubuntu-desktop

If your using using Gnome Shell

sudo apt-get install --reinstall gdm3 gnome-shell

Reconfigure lightdm, set it as the default login manager

sudo dpkg-reconfigure lightdm

Replace GDM with LightDM

sudo apt-get remove gdm3 
sudo apt-get install lightdm

Installing GDM (Gnome Login Manager)

sudo apt-get install gdm3

Remove Intel video and Plymouth

sudo apt-get remove xserver-xorg-video-intel plymouth

Reboot, get to a prompt and reinstall login manager, replace lightdm with whatever one your using

sudo apt-get install --reinstall lightdm

Reinstall Intel video and Plymouth

sudo apt-get install xserver-xorg-video-intel plymouth

Install Ubuntu Gnome Desktop

This seems to solve some of the issues with GDM3 not starting up.

sudo apt-get install ubuntu-gnome-desktop

 

Install Slackcat on Raspberry Pi (Raspbian)

Slackcat allows you to send Slack messages from the Linux command line.

Update pi

sudo apt-get update

Install Ruby and other components

sudo apt-get install ruby1.9.1 ruby ruby-dev rubygems

Install Slackcat

sudo gem install slackcat

Use Slackcat.  You will need to generate an API Key from Slacks website.

echo "Hello World" | slackcat -k API-KEY -p --channels=#CHANNEL_NAME

Examples :
Send to Channel

echo "Hello World" | slackcat -k xoxp-94827839414-94819543146-441447827184-h7dt2hg2h8ggs7d24ce638edrw9q8def -p --channels=#General

Send Direct Message

echo "Hello World" | slackcat -k xoxp-94827839414-94819543146-441447827184-h7dt2hg2h8ggs7d24ce638edrw9q8def -p --users=#General

 

Set Bash as users default shell

You can change the default shell for a Linux user with the following command.  Change “/bin/bash” to whatever shell you want and replace USERNAME with the Linux user.

chsh /bin/bash USERNAME

Enter in the users password and then log out and back in and the users shell will be whatever shell you specified.  In this case bash.

You can also do this by manually editing the /etc/passwd file.  Find the user by their username, and then replace the last part of the line with the new shell path.

Some Linux distributions (like Kali Linux) use /bin/sh as the default shell for new users.  Changing it to bash makes the shell a little more usable.

Cannot open mailbox /var/mail/pi: Permission denied

This is on a Raspberry Pi, but should be the same on any Linux distro.

Error :

pi@raspberrypi:~ $ mail
Cannot open mailbox /var/mail/pi: Permission denied
No mail for pi
pi@raspberrypi:~ $ 

Fix :

sudo touch /var/mail/$USER
sudo chown $USER:mail /var/mail/$USER
sudo chmod 660 /var/mail/$USER

You can replace “$USER” if you need to run the commands for a different account.
Example:

sudo touch /var/mail/pi
sudo chown pi:mail /var/mail/pi
sudo chmod 660 /var/mail/pi

How To export private SSH key on Linux

All that needs to be done is the “id_rsa” key needs to be copied to the “new” host.  You can do this with SCP or sftp.

Example with SCP

The following examples are showing how to export a RSA private key, if your using DSA, then replace id_rsa with id_dsa.

Copy private key from remote server to local machine for the local user

scp root@192.168.1.1:~/.ssh/id_rsa ~/.ssh/

Copy private key from localhost to remote host.  This command copies the local users private key to the root user @ 192.168.1.1

scp ~/.ssh/id_rsa root@192.168.1.1:~/.ssh/

 

How To remove a ZenPack from Zenoss 5

To remove a ZenPack on Zenoss 5.1 and later, you are going to need to stop the zenoss services, restart a couple services that are needed to install the ZenPack, install the ZenPack, and then restart the Zenoss service.

Stop Zenoss.Core

serviced service stop Zenoss.Core

Make sure the service is stopped by running the following command.  When it reports back the Zenoss is Stopped, then continue.

 if ( serviced service status Zenoss.Core | awk '{print $3}' | grep -q Stopped) ; then echo "Zenoss is not running!" ; else echo "Zenoss is not Stopped!" ; fi

Or you can run this command, just make sure it says it is stopped.

serviced service status zenoss.core

Create a Snapshot

serviced service snapshot Zenoss.core

Start the following three services

serviced service start Infrastructure
zeneventserver
Zope

serviced service start Infrastructure
serviced service start zeneventserver
serviced service start Zope

List the ZenPacks that are currently installed.

serviced service run zope zenpack list

Remove the ZenPack.  Replace “ZenPack.comunity.Zenpack” with the zenpack name from the previous command.

serviced service run zope zenpack-manager uninstall ZenPack.community.Zenpack

How To use the Zenoss Toolbox

This is all contained in the Zenoss Upgrade guide.

Attach to Zope

serviced service attach zope/0
su zenoss

You can run the following commands to check on zenoss

zenossdbpack
findposkeyerror
zenrelationscan
zencatalogscan

zenossdbpack : Quickly scans the Zope Object Database (ZODB) to provide a preliminary indication of the health of the database, and to determine whether the database needs to be compressed with “zenossdbpack” before upgrading.
findposkeyerror : Checks objects and their relationships, and provides options for fixing errors.
zenrelationscan : Checks only ZenRelations between objects.
zencatalogscan : Checks ZODB object catalogs, which speed up web interface access

How To Install the Zenoss Tool Box

Skip to the bottom if you just want to see all of the commands.

Make a temporary directory

mkdir /tmp/toolbox
cd /tmp/toolbox

Download the tool box

wget https://github.com/zenoss/zenoss.toolbox/archive/master.zip
chmod -R 777 /tmp/toolbox

Drop to a shell and switch user

serviced service shell -i -s ToolBox zope bash
su zenoss

Install

easy_install /mnt/pwd/master.zip

Exit and commit container

exit
exit
serviced snapshot commit ToolBox

Restart Zope

serviced service restart zope

 

All the commands:

mkdir /tmp/toolbox && cd /tmp/toolbox
wget https://github.com/zenoss/zenoss.toolbox/archive/master.zip
chmod -R 777 /tmp/toolbox
serviced service shell -i -s ToolBox zope bash
su zenoss
easy_install /mnt/pwd/master.zip
exit
exit
serviced snapshot commit ToolBox
serviced service restart zope