Showing posts with label shell. Show all posts
Showing posts with label shell. Show all posts

Wednesday, May 6, 2009

cygwin shell syntax error near unexpected token

This is a common error and the reason is your are using Windows to create the file. Thus the line break is \r\n rather than \n.

All you need to do is change the format using a system command:

dos2unix filename_here

Monday, August 11, 2008

How to backup Linux to FAT32 External Drives

There is very good tutorial on this issue, however, i wanted to add a bit more. How to backup Linux to FAT32 External Drives | WickedBlog
The backup process sounds pretty easy, but indeed, there are heaps problems when you actually working on it.

I am a windows user, and nowadays, most product are targeting windows user.  I developed the backup utility for the SMEServer (e-smith server) and First of all,
the priority is that things can be extract in Windows.  Obviously , NTFS is not a good option cause it is not supported in SMEServer.  So Fat32 was chosen and I didn't realise the file size limit of 4G until some time had passed and all my backups are smaller than 4G.

Let's begin with backup first.

tar -czf /media/DRIVENAME/BACKUPNAME.tgz /home

This is the real simple solution to backup one folder, and of course, we have more to backup.  So, we introduce the following one:

'tar -cz --files-from '+ FILELIST_TAR + ' > ' + TAR_OUTPUT+'.tgz'

NOTE that I now read files from a list, and this is recommended to do only when programming.

Finally, we need to split it

'tar -cz - --files-from '+ FILELIST_TAR + ' |  split -b 3880m - ' + TAR_OUTPUT+'.tgz'

Re-constitute properly with this customized restore command:

cat /media/DRIVENAME/BACKUPNAME.tgz.* | tar -zxf -

And of course, I didn't forget the windows user, you can re-constitute the files like this:
copy /b BACKUPNAME.tgz.* ALL_IN_ONE.tgz /b

Enjoy

Thursday, August 7, 2008

using MD5 to compare folder python script

I have been working with linux for almost 1 year now. Still, I like Windows better. Haha

This is a problem i recently trying to solve. When I using cp -r command to copy a folder, or burn a folder onto dvd, i wonder if the copy that i created is 100% correct. To do this, I use md5sum to calculate md5 of the individual files in this folder.

Here is the python script :


#!/usr/bin/python


# perform a shell command and get it's output
from commands import getoutput
# perform a shell command and get it's status (error code)
from commands import getstatusoutput
# get exit, and command line args
from sys import exit,argv

#oldPWD=getoutput('pwd')

p1md5=getoutput('(cd "' + argv[1] + '"; find . ) | sort | md5sum -b')
#print p1md5

p2md5=getoutput('(cd "' + argv[2] + '"; find . ) | sort | md5sum -b')
#print p2md5

#getstatusoutput('cd "' + oldPWD + '"')

if p1md5 == p2md5:
print "Success"
exit (0)
else:
print "Fail"
exit (1)