Follow Island in the Net on WordPress.com

Old Code

Usage

ftp.pl [-netrc] [-u <i>user</i>] [-p <i>passwd</i>] -m server -s source_dir -t target_dir [-log_dir <i>/path/to/logs/file</i>] file1 file2 ...

# Copyright 2000 Williams Interactive, Inc.
# Programmer: Khurt Williams, 2000.10.18
# command switches are
# -netrc : uses .netrc file to find user/passwd for the destination server 
# -u <i>user</i> : specify the user id
# -p <i>passwd</i> :specify the passwd for user id
# -m server : server ip or name
# -s source_dir : source dir
# -t target_dir : target dir
# -log_dir <i>/path/to/logs/file</i> : location of log file

Code

#!/usr/local/bin/perl -w
# Copyright 2000 Williams Interactive, Inc.
# Programmer: Khurt Williams, 2000.10.18
# command switches are
# [-netrc] : uses .netrc file to find user/passwd for the destination server 
# [-u user] : specify the user id
# [-p passwd] :specify the passwd for user id
# -m server : server ip or name
# -s source_dir : source dir
# -t target_dir : target dir
# [-log_dir /path/to/log] : location of log file

use strict;
use Getopt::Long;
use Net::FTP;
use Net::Netrc;
use Log::ErrLogger;

my ($log_file,@file_list,$file,$return_code);
my ($netrc,$server,$source,$target,$user,$passwd,$log_dir,$ftp);
my ($machine,$login,$password);
my $options = { netrc => \$netrc, m => \$server, s => \$source, t => \$target, u => \$user, p => \$passwd, log_dir => \$log_dir };

GetOptions($options, "netrc","m=s","s=s","t=s","u:s","p:s","log_dir:s");

@file_list = @ARGV;

#make sure we have some filename
usage() if( !defined(@file_list) );

#use netrc
if( $netrc ) {
#exit if not server specified
 usage () if( !defined($server) );
#make sure we use the correct userid
 if( !defined($user) ) {
  $machine = Net::Netrc->lookup($server);
 }
 else {
  $machine = Net::Netrc->lookup($server,$user);
 }
#get login id and password for that server
 $login = $machine->login();
 $password = $machine->password();

 $user = $login;
 $passwd = $password;
}

#check that command line switches are set
usage() if( !defined($user) || !defined($passwd) || !defined($server));
usage() if( !defined($source) || !defined($target));

#append to log file if it already exist
$log_dir = "/tmp" if( !defined($log_dir) );
#log all event to file including die and warn
$log_file = new Log::ErrLogger::File( FILE => ">$log_dir/SendToML.log",SENSITVITY => Log::ErrLogger::ALL );

#connect to server
$ftp = new Net::FTP($server);
Log::ErrLogger::log_error(Log::ErrLogger::INFORMATIONAL,__FILE__." ftp started.\n");
Log::ErrLogger::log_error(Log::ErrLogger::INFORMATIONAL,"ftp $server\n");
#exit and log message on failure
die($ftp->message()) if( !($ftp->login($user,$passwd)) );

#set mode to binary
Log::ErrLogger::log_error(Log::ErrLogger::INFORMATIONAL,"bin\n");
#exit and log message on failure
die($ftp->message()) if( !($ftp->binary()) );

#change local directory
chdir($source);
Log::ErrLogger::log_error(Log::ErrLogger::INFORMATIONAL,"lcd $source\n");

#change remote directory
Log::ErrLogger::log_error(Log::ErrLogger::INFORMATIONAL,"cd $target\n");
#exit and log message on failure
die($ftp->message()) if( !($ftp->cwd($target)) );

foreach $file (@file_list) {
#send files to server
 Log::ErrLogger::log_error(Log::ErrLogger::INFORMATIONAL,"put $file $file\n");
 retry_put($file) if( !($ftp->put($file,$file)) );
}

#close connection
$return_code = $ftp->quit();
Log::ErrLogger::log_error(Log::ErrLogger::INFORMATIONAL,"quit\n");
Log::ErrLogger::log_error(Log::ErrLogger::INFORMATIONAL,__FILE__." ftp ended.\n");

#end logging
$log_file->close();

exit(0);

sub usage {
 die "$0 [-netrc] [-u user] [-p passwd] -m [server]  -s [source_dir] -t [target_dir] [-log_dir [/path/to/logs/file]] file1 file2 ...\n";
}

#resend file if first attempt fails
#remove file if second attemp also fails.
sub retry_put {
 my ($file) = @_;

 warn($ftp->message());
 Log::ErrLogger::log_error(Log::ErrLogger::INFORMATIONAL,"Will attempt to resend file %s.\n",$file);

 warn($ftp->message()) if( !($ftp->quit()) );
 Log::ErrLogger::log_error(Log::ErrLogger::INFORMATIONAL,"quit\n");

 $ftp = new Net::FTP($server);
 Log::ErrLogger::log_error(Log::ErrLogger::INFORMATIONAL,"ftp $server\n");
 die($ftp->message()) if( !($ftp->login($user,$passwd)) );

 Log::ErrLogger::log_error(Log::ErrLogger::INFORMATIONAL,"cd $target\n");
 die($ftp->message()) if( !($ftp->cwd($target)) );

 Log::ErrLogger::log_error(Log::ErrLogger::INFORMATIONAL,"put $file $file\n");
 remove_file($file) if( !($ftp->put($file,$file)) );
}

sub remove_file {
 my ($file) = @_;

 warn($ftp->message());
 Log::ErrLogger::log_error(Log::ErrLogger::INFORMATIONAL,"Resend of $file failed.\n");
 Log::ErrLogger::log_error(Log::ErrLogger::INFORMATIONAL,"Will attempt to remove half baked file $file.\n");

 warn($ftp->message()) if( !($ftp->quit()) );
 Log::ErrLogger::log_error(Log::ErrLogger::INFORMATIONAL,"quit\n");

 $ftp = new Net::FTP($server);
 Log::ErrLogger::log_error(Log::ErrLogger::INFORMATIONAL,"ftp $server\n");
 die($ftp->message()) if( !($ftp->login($user,$passwd)) );

 Log::ErrLogger::log_error(Log::ErrLogger::INFORMATIONAL,"cd $target\n");
 die($ftp->message()) if( !($ftp->cwd($target)) );

 Log::ErrLogger::log_error(Log::ErrLogger::INFORMATIONAL,"delete $file\n");
 warn($ftp->message()) if( !($ftp->delete($file)) );
}

Is it Time for a Diabetes Offline Community?

Kelly Close of diatribe.org asked an intriguing question on Twitter last week. Kerri Sparling responded with a blog post and Doug Tallman responded to Kerri's post.

Here's Kelly's tweet:

Doug's blog post reminded me of something I've thought about for a while. He is suggesting that the diabetes community needs some sort of mentorship or support group. Here's that part of Doug's post that got my attention.

Things like this occur already online, and lots of good can come from a blog, a Twitter chat, and a Facebook page. But if we want to effect real change, I think it’s going to have to happen face to face. Maybe a dozen people. Sitting in a circle of folding chairs. Possibly in a church basement or an empty meeting room in a government building. The room should be redolent of fresh-brewed coffee. And maybe a dozen donuts for the members who bolused.

While I occasionally take part in the DSMA Twitter event and get "in it" on Tudiabetes.org, I still feel a bit isolated. The JDRF is very active in the area but as one blogger recently noticed, the JDRF feels like a kids-only organization. I only know two other adults with T1 in New Jersey. One of them started a group similar to what Doug was suggesting. But it quickly turned got taken over by T2 seeking advice on diet and exercise. They weren't as interested in talking about insulin, and pumps and CGMS etc.

Right now, I am struggling with weight and exercise. Frankly, I don't exercise and I am 10kg overweight. My BMI is borderline at 25. I am taking statins to manage my cholesterol. When I worked at Sarnoff, I was part of a walk team. A few of us would take 30 minutes from our schedule for a walk around the Nassau Park Pavillions complex. It's a brisk 2.4km walk. We would talk about family and life etc. It worked well for me. But that was two years ago. I consult now and the new work environment is not conducive to walking during the day.

So ... here I am thinking. This is my problem. I could solve this one myself. I could start a group. I could let people on twitter and tudibaetes.org know what I was doing. Then I could go sit in one of the meeting rooms in the Princeton Public Library or the Panera and just wait. Maybe someone will show up.