PERL ^M stripper

Posted by ljmacphee on February 15, 2007 under linux, osx, perl, tools | Be the First to Comment

I had to restore the website from a Windows back up a few months ago. Yuch! I couldn’t find any ^M strippers that did more than one file at a time (there are over 2,500 files here !!) so I wrote one.^M Stripper

Updated 10/0312/01
A tool for stripping those Windows line control characters from your files.

Copy the original files to a temporary directory.

At a command prompt type:./strip.pl directoryname
and it will strip the ^M’s from those files.

strip.pl 


Source Code 

#!/usr/bin/perl 
#This program removes the Window’s ^M line control
#characters from all the files in a subdirectory.
#type ./strip.pl at the command line
#followed by the name of the directory with the files to be fixed
#./strip.pl directoryname

#no warranties are given or implied.
#use at your own risk

#get sub-directory in which files to be fixed are located
#to use this program make sure it is executable
#chmod 755 strip.pl
#to run this program
#./strip.pl directoryname
#directory name being the name of the directory with your files that
#need to be fixed. 

$directory = @ARGV[0];chomp($directory);
#switch to sub-directory of files to scan and change
#read current working directory and store file names in@flist

opendir( INDIR, “./$directory”) || die (”$0: Can not read directory”);

while( $fname = readdir INDIR){
next if $fname =~ /^\./;

#not hidden
next if $fname =~ /^\.\.?$/;

#it’s pwd or parent
next if $fname =~ “strip.pl”;

#not me
push @flist, $fname;

}

closedir(INDIR);

system (”cd $directory”);

foreach $fn (@flist) {
open( IN, “$directory/$fn”) || die (”\n can not read $fn \n”);
open( OUT, “>temp”) || die (”\n can not write $fn \n”);
$flag = 0;
$lineNo = 0;

while( ){
$lineNo++;
$line = $_;
$line =~ s/\r//g;
print OUT “$line”;
}

close(IN);
close(OUT);

rename (temp, $fn) || die “couldn’t rename temp to $fn.\n”;
}

Webcam set up under linux

Posted by ljmacphee on February 3, 2007 under how to, linux, tools, webcam | Be the First to Comment

{most recent webcam shot}

Ok, the webcam is backup and running. The setup is a bit different now.

For those using newer 2.4.5+ kernels the driver is built in, but you have to recompile your kernel. You will also want to download the pwcx driver from the Philips camera driver page.

If you are running an older kernel in which the webcam driver is not built in, pre 2.4.5 then you need to download the driver from the Philips camera driver page. and install it. He gives excellent step by step instructions for doing so.

For the older kernels I used Camserv at Source Forge. It compiled and ran totally painlessly.

If you are using a newer kernel 2.4.5+ then recompile your kernel with the built in philips camera driver. Be sure to turn on usb, the camera, input core support and event interface support. You will need to download and add in the pwcx kernel from the Philips camera driver page. He gives excellent instructions for doing so.

I downloaded his camstream program (also on the philips driver page) but vjgrabber works just as well. Use either of these programs to grab the pictures and write them to a file. I made a webcam directory off my home directory and stuck everything in there.

To ftp the pictures up to your website you need to add a routine to your .bashrc file, write an upload script and add or create an entry in the .netrc file. Instuctions for each follow:

The .netrc file belongs in your home directory. Be sure permissions are set to 600. If you don’t have one already just create a file with these three lines substituting yourwebsite.com, yourloginname, and yourpassword.

machine yourwebsite.com
login yourloginname
password yourpassword

Add this to your .bashrc file

upload is the name of the script that does the uploading, you can name it whatever you like and just change the name here. Sleep is the number of seconds between uploads. Set this to what ever you like.

function webcam()
{

export LOOP=”true”
while [ $LOOP = "true" ]; do
ftp < upload
sleep 300
done

}

This is the upload file. Snapshot.jpg is the name of the picture that camstream takes.

open yourwebsite.com
prompt
binary
cd yourwebcamdirectory
put snapshot.jpg
bye

I put the snapshot.jpg and upload in a webcam directory.
Once you done all of this, open a new shell so .bashrc will run again.
Start the program that is taking the pictures and have them saved
in this directory as snapshot.jpg. I just overwrite the previous
one.

In the webpage I put the following 2 lines after the heading and before the body, this seems to work refreshing the page.

< /head>
< META HTTP-EQUIV=”refresh” content=”300″>
< META HTTP-EQUIV=”Pragma” content=”no-cache”>
< body>