Random Unix/Linux Tips

Yeah, that's pretty much the subtitle of this blog, but I found another that has similar stuff:

http://users.softlab.ece.ntua.gr/~ttsiod/tricks.html

My favs (I'm copying in case the site goes down):

Convert a static lib (.a) into a dynamic one (.so)

gcc -shared -o libXxf86vm.so.1.0 \
	-Wl,-soname,libXxf86vm.so.1 \
	-Wl,--whole-archive,libXxf86vm.a,--no-whole-archive

Create PNGs from a pdf presentation

gs -dSAFER -dBATCH -dNOPAUSE -dTextAlphaBits=4 \
    -dGraphicsAlphaBits=4 \
    -r85 -q -sDEVICE=png16m -sOutputFile=icfp-pg%02d.png \
    PhDPresentation.pdf

Read a damaged CD/DVD valid parts and get the rest with rsync

As is often the case, when I bring some burned CD/DVD 
from work, I find out that its bad at some offset.
I came up with this Perl script:

---------------------------------------
#!/usr/bin/perl -w
use strict;

my $i=0;

select((select(STDOUT), $| = 1)[0]);
unlink("data");

system("dd if=/dev/zero of=zero bs=2K count=1");

my $step = 1;

print "Sector:             ";
while(1) {
 system("dd if=/cdrom/BadSector of=sector bs=2K skip=$i".
    "count=1 >/dev/null 2>&1");
 if ($? == 0) {
     print sprintf("\b\b\b\b\b\b\b\b%08d", $i);
     system("cat sector >> data");
     $step = 1;
     $i += $step;
 } else {
     system("cat zero >> data");
     $step += $step;
     $i += $step;
     print "\nJumped over $step\nSector:             ";
 }
}
-----------------------------

With the CD/DVD mounted on /cdrom/, it will slowly but 
effectively copy sector by sector of the file mentioned 
in the 'dd' line into the file called 'data'. Reading 
sector-sector proves to be enough to correct a multitude 
of read-errors on my DVD reader, but even if that isn't 
enough, it will quickly jump over the problem areas
in the DVD, writing blank 'sectors' to mark the jumps.

After that, rsync can save the day:

rsync -vvv -B 131072 -e ssh \
	[email protected]:/path/todata data

Comments

No comments.