Wednesday, March 7, 2012

Automating Task on Linux

If you have been looking for a way to Automate a task on Linux, then this is the place for you. We used this in a bid to Automate SquirrelMail Backup on Ubuntu 9.04

Open /etc/crontab and add the following line in it:
50 08 * * * root /bak
This indicates that the executabe file named bak in / will run everyday at 08:50 am
we created the /bak file to backup IMAP folders in SquirrelMail on Ubuntu 9.04

To learn how to schedule a task in Windows, click here.

Schedule a task on Windows

If you are looking to Schedule a task on Windows or automate a task on Windows then you have indeed come to the right place. Read on...
We tried this on Windows XP with SP2:

Click on Start button
Click on All Programs
Click on Accessories
Click on System Tools
Click on Scheduled Tasks
Click on File
Click on New
Click on Scheduled Task
Name it what you want to.
Double click on it.
Click on Browse and select the program yo would like to run; in our case it was the batch file that we created here to copy a file from Linux to Windows.
Click on the Schedule tab and schedule task as per your needs.
I used Daily. Set the start time as per your requirement.
This will automatically carry out the task for you at the predefined time. This way I am able to automatically get the file copied from Ubuntu 9.04 to Windows. Only make sure the WIN XP is on at the predefined time.
If you might be interested in learning how to copy a file from Windows to Linux, read about it here.


I found this solution in a bid to Backup SquirrelMail on Ubuntu 9.04. If you want to learn how to automate a task on Linux, check it out here.

Automating SquirrelMail Backup on Ubuntu 9.04

If you are looking to automate SquirrelMail Backup on Ubuntu 9.04 or on any other flavor of Linux for that matter, read on...

Create a file called bak with the following contents and chmod 744 bak to make it executable.
rm  /backup/*.zip
rm -rf /backup/user_name
/usr/local/imap_tools/imapdump.pl  -f /backup/user_name -S localhost/user_name@your_domain/user_password
zip -r /backup/user_name_`date '+%d%m%Y'` /backup/user_name/.


The first line will delete any zipped files existing in the backup folder called backup in this case.

The second line will delete the backup of the IMAP folders that already exist from last time's backup. This is important since if the user had 20 emails in the last backup and he has thereafter deleted 5 emails that he does not require, the numbers get moved up and he will have 15 emails backed up numbering from 1 to 15 which will overwrite the emails numbered 1 to 15 from the previous backup. But the numbers 16 to 20 will still exist giving the user emails that he did not want and had deleted in case you want to restore SquirrelMail backup. Hence the deletion of the entire tree structure. The command rm -rf foldername removes the entire directory tree with all its files and subfolders and files.It is the Linux equivalent of deltree on DOS.

The third line backs up the IMAP folders of user user_name with password user_password on domain your_domain, storing it in folder /backup/user_name.

The fourth line zips the folder contents with subfolders and files creating a file with the username followed by date in DDMMYY format.

Learn how to copy a file from Linux to Windows here.

Restore SquirrelMail Backup

If you are looking to restore SquirrelMail backup, then you can follow the how to here:
First, copy the backup file from Windows to Linux using the instructions here. Or if it is already on Linux, you have nothing to worry about.

cd /backup 
where backup is the folder where you backup squirrelmail and zip it.

Just unzip the zipped file by giving the command:
unzip zipfilename -d tmpThis will unzip the folders and files under tmp folder.

If you have followed the instructions on how to Backup SquirrelMail on Ubuntu 9.04 then you will have already copied dumptoIMAP.pl to /usr/local/imap_tools.


Create a user called test using ISPConfig.
The following command will restore the INBOX from SquirrelMail to user testuser.
/usr/local/imap_tools/dumptoIMAP.pl -i localhost/test@genopharma.com/password -L dumptoIMAP.log -D /backup/tmp/backup/username/INBOX -m INBOX


You will have to restore each mail folder this way. The following command will restore the Sent folder. 

/usr/local/imap_tools/dumptoIMAP.pl -i localhost/test@genopharma.com/password -L dumptoIMAP.log -D /backup/tmp/backup/username/INBOX.Sent -m INBOX.Sent


You will have to do this for as many mail folders that might exist for that user.

Copy a file from Windows to Linux

If you are looking to copy a file from Win XP to Ubuntu 9.04:

On your Windows PC, download pscp.exe from here.

Suppose you copied the pscp.exe to a folder called linux on D drive and the file you want to transfer from Windows to Linux is bak.zip then the command :
d:\linux\pscp.exe d:\bak.zip linux_user@linux_ip_address:/windows
will copy the d:\bak.zip to a folder called windows under / on Linux.

If you get an error like :
pscp: unable to open <file name>: permission denied.
It means that the linux_user you are looing into the server with does not have write permissions to the specified folder called windows in this case. This folder was probably made by su or at least logged in as sudo su.
Run the following command logged in as sudo su to eliminate this problem.
chown linux_user /windows

To learn how to transfer a file from Linux to Windows, click here.

How to copy a file from Linux to Windows

If you are looking to copy a file from Linux to Windows, look no further.
Download pscp.exe from here. The one I downloaded earlier gave me the error : pscp.exe is not a valid win32 application. Hence, I downloaded it from here.
On your Windows PC, create a folder. I created d:\bak on my WIN XP PC and copied the pscp.exe there. I also ran a batch file called bak.bat which contains:
pscp.exe -pw users_password user@server_ip_addr:/backup/*.zip d:\bak

This will copy all the zip files from the backup folder on your Linux machine to the bak folder in the D drive of your Windows PC. This was tested on a PC running WIN XP.

If you would like to learn how to copy a file from Windows to Linux, click here.

Zip folder with subfolders in Linux

If you are looking to zip folder in Linux with all its contents including subfolders you can make use of this :

zip -r zip_file_name  /path_of_folder_with_subfolders

For example :
zip -r backup  /backup/user
will  backup the entire contents of /backup/user including files and subfolders to a file backup.zip


How to Backup SquirrelMail on Ubuntu 9.04

If you have been looking for ways to backup SquirrelMail then this is the place for you.
To start with, I found that the emails are stored one in each file in /var/vmail/our-domain-name/user/cur when read and in /var/vmail/our-domain-name/user/new when unread. I tried to make a test user using ISPConfig and copied the mail folder /var/vmail/our-domain-name/user to /var/vmail/our-domain-name/testuser but I did not get the results that I was looking for. After searching the Net and learning a few things, I have come up with this how-to for other Linux enthusiasts so that they can easily backup SquirrelMail.

After logging in as sudo su:
1. Create a folder called imap_tools under /usr/local.

2. Download these files to this folder : 
    imapdump.pl : This is to backup the squirrel mail folders or IMAP folders 
   dumptoIMAP.pl : This is to put the backed up folders back into SquirrelMail if ever the need arises due to a server crash or some such.  

3. Create a folder called backup under root (/). You can create one with a different name or in some other location if you wish. 

4. /usr/local/imap_tools/imapdump.pl -f /backup/user -S localhost/user@yourdomain/users-passwd
This command will backup SquirrelMail folders belonging to user to the /backup/user folder. You will have one folder for each mailbox and the emails will be stored therein, one file per e-mail.

5. zip -r /backup/user_`date '+%d%m%Y'` /backup/user/
This command will create a file called user_07032012 (if today's date is 07/03/2012) in the /backup folder by zipping the folders and files under /backup/user. This is your answer if you did not know how to zip a folder with its subfolders in Linux or how to zip folder recursively on Linux.

6.  Next download pscp.exe from here. The one I downloaded earlier gave me the error : pscp.exe is not a valid win32 application. Hence, I downloaded it from here.

7. On your Windows PC, create a folder. I created d:\sqbak on my WIN XP PC and copied the pscp.exe here. I also created and ran a batch file called sqbak.bat which contains:
pscp.exe -pw users_password user@server_ip_addr:/backup/*.zip d:\sqbak 
This is your answer to copy a file from Linux to Windows.
To schedule this task to automatically copy a file from Linux to Windows, you can make use of the Scheduler available in Windows. For more information, click here.

8. The zipped file will now be backed up from your Linux server onto your Windows PC in d:\sqbak.

9. To check whether your SquirrelMail backup is authentic or to restore SquirrelMail backup in case of a server crash or when you upgrade to a new server or a later version of Linux.

Thursday, March 1, 2012

Transfer music from PC to iPhone

Here you will learn how to copy songs from PC to iPhone, copy songs from PC to iPod or copy songs from PC to iPad.

Now that we managed to successfully transfer music files from iPod to PC, we were now asked to transfer the files from PC to iPhone. One can do it using iTunes, but it is always at a risk since the synchronization might happen in the wrong direction and you might be left with your existing files wiped out.

This time we downloaded another software that we got for free, the Copy Trans Suite (Install_CopyTrans_Suite.exe) which we downloaded here. This time we used the Apple iPhone A1387 model. However, when we installed the software, it did not detect the iPhone. We did a restart although it didn't ask us to and thereafter it detected the iPhone as a 4S. We then successfully copied the files from the PC to the iPhone.

You can use this how-to to transfer music files from PC to iPad and also to transfer music files from PC to iPod.

Transfer music from iPod to PC

Here you will learn how to copy songs from iPod to PC, copy songs from iPhone to PC or copy songs from iPad to PC.

If you have been looking to find out how to transfer music files from your iPod to your PC, you have indeed come to the right place. You  may use iTunes but this is very risky as if you don't turn off the synchronizing option, you can lose all your music files from your iPod.

Hence, we looked for something else other than iTunes.We used iPod PC Transfer Suite (ipssetup.exe) which we downloaded here. This is a software that can be purchased for something like $30. In this free trial, you can save the music files to compute but then you have to click on each one and save manually; you cannot save them all at one shot for which you have to purchase the software. This was a painstaking job considering there were about 150 files on the iPod. But it worked well and safely. We tried this out on an iPod A1288 model.

However, you can use this how-to to transfer music files from iPhone to PC and also to transfer music files from iPad to PC.

Next, we were given the task of transferring these music files from PC to iPhone. Read about it here.