$ ls -al
total 24
drwxr-xr-x 2 fred automation 4096 Sep 18 15:11 .
drwxr-xr-x 5 fred automation 4096 Sep 18 14:05 ..
-rw-r--r-- 1 fred automation 358 Sep 18 15:11 eng_captions
-rw-r--r-- 1 fred automation 307 Sep 17 19:49 eng_captions~
-rw-r--r-- 1 fred automation 97 Sep 17 23:21 f
-rw-r--r-- 1 fred automation 74 Sep 17 22:16 f~
$ cd ..
$ pwd
/home/fred/Documents/root/pages/terminal
$ ls -l
total 24
drwxr-xr-x 2 fred automation 4096 Sep 18 15:11 captions
-rw-rw-r-- 1 fred automation 793 Aug 26 17:08 ident.txt
drwx------ 2 fred automation 4096 Sep 17 14:54 images1
drwxrwxr-x 2 fred automation 4096 Sep 17 19:49 template_stuff
-rwxr-xr-x 1 fred automation 3664 Sep 18 00:11
terminal1.pl
-rwxr-xr-x 1 fred automation 3664 Sep 18 14:05
terminal2.pl
$ ./
terminal2.pl my_ftp
files are images1/s1.png
Net::FTP>>> Net::FTP(2.77)
Net::FTP>>> Exporter(5.64_03)
Net::FTP>>> Net::Cmd(2.29)
Net::FTP>>> IO::Socket::INET(1.31)
Net::FTP>>> IO::Socket(1.32)
Net::FTP>>> IO::Handle(1.31)
Net::FTP=GLOB(0x896171c)<<< 220 FTP Server ready.
Net::FTP=GLOB(0x896171c)>>> USER u61210220
Net::FTP=GLOB(0x896171c)<<< 331 Password required for u61210220
Net::FTP=GLOB(0x896171c)>>> PASS ....
Net::FTP=GLOB(0x896171c)<<< 230 User u61210220 logged in
Net::FTP=GLOB(0x896171c)>>> TYPE I
Net::FTP=GLOB(0x896171c)<<< 200 Type set to I
Net::FTP=GLOB(0x896171c)>>> CWD /pages
Net::FTP=GLOB(0x896171c)<<< 250 CWD command successful
Net::FTP=GLOB(0x896171c)>>> PASV
Net::FTP=GLOB(0x896171c)<<< 227 Entering Passive Mode
(74,208,244,112,208,51).
Net::FTP=GLOB(0x896171c)>>> NLST
Net::FTP=GLOB(0x896171c)<<< 150 Opening BINARY mode data connection for
file list
Net::FTP=GLOB(0x896171c)<<< 226 Transfer complete
matching is 1 2 3
new word is terminal_4
html file is terminal_4.html
Net::FTP=GLOB(0x896171c)>>> CDUP
Net::FTP=GLOB(0x896171c)<<< 250 CDUP command successful
Net::FTP=GLOB(0x896171c)>>> CWD images/
Net::FTP=GLOB(0x896171c)<<< 250 CWD command successful
Net::FTP=GLOB(0x896171c)>>> MKD terminal_4/
Net::FTP=GLOB(0x896171c)<<< 550 terminal_4/: File exists
Cannot create directory terminal_4/: File exists
Net::FTP=GLOB(0x896171c)>>> CDUP
Net::FTP=GLOB(0x896171c)<<< 250 CDUP command successful
files are captions/eng_captions captions/eng_captions~ captions/f
captions/f~
text is This shows three different ways to get lines 35 to 38 in a file
called
bc1.pl. This script is new and is supposed to take the hyperlink
I post right here, and expand it properly to html:
http://www.youtube.com/watch?v=6qBwCmhIHq0 . Everywhere we hear the
sounds of revolution; we just don't see any.
The square root of 3 is Washington's birthday: 1732.
text is <p class="hft-paras">This shows three different ways to get
lines 35 to 38 in a file called
bc1.pl. This script is new and is
supposed to take the hyperlink I post right here, and expand it properly
to html: <a href="
http://www.youtube.com/watch?v=6qBwCmhIHq0"
class="hft-urls">
http://www.youtube.com/watch?v=6qBwCmhIHq0</a> .
Everywhere we hear the sounds of revolution; we just don't see any. </p>
<p class="hft-paras">The square root of 3 is Washington's birthday:
1732.</p>
Net::FTP=GLOB(0x896171c)>>> CWD /images/terminal_4/
Net::FTP=GLOB(0x896171c)<<< 250 CWD command successful
name is images1/s1.png
remote is s1.png
Net::FTP=GLOB(0x896171c)>>> ALLO 93069
Net::FTP=GLOB(0x896171c)<<< 200 ALLO command successful
Net::FTP=GLOB(0x896171c)>>> PASV
Net::FTP=GLOB(0x896171c)<<< 227 Entering Passive Mode
(74,208,244,112,217,190).
Net::FTP=GLOB(0x896171c)>>> STOR s1.png
Net::FTP=GLOB(0x896171c)<<< 150 Opening BINARY mode data connection for
s1.png
Net::FTP=GLOB(0x896171c)<<< 226 Transfer complete
Net::FTP=GLOB(0x896171c)>>> PWD
Net::FTP=GLOB(0x896171c)<<< 257 "/images/terminal_4" is the current
directory
Net::FTP=GLOB(0x896171c)>>> PASV
Net::FTP=GLOB(0x896171c)<<< 227 Entering Passive Mode
(74,208,244,112,251,94).
Net::FTP=GLOB(0x896171c)>>> NLST
Net::FTP=GLOB(0x896171c)<<< 150 Opening BINARY mode data connection for
file list
Net::FTP=GLOB(0x896171c)<<< 226 Transfer complete
Net::FTP=GLOB(0x896171c)>>> CDUP
Net::FTP=GLOB(0x896171c)<<< 250 CDUP command successful$ ls -l
total 24
drwxr-xr-x 2 fred automation 4096 Sep 18 15:11 captions
-rw-rw-r-- 1 fred automation 793 Aug 26 17:08 ident.txt
drwx------ 2 fred automation 4096 Sep 17 14:54 images1
drwxrwxr-x 2 fred automation 4096 Sep 17 19:49 template_stuff
-rwxr-xr-x 1 fred automation 3664 Sep 18 00:11
terminal1.pl
-rwxr-xr-x 1 fred automation 3664 Sep 18 14:05
terminal2.pl
Net::FTP=GLOB(0x896171c)>>> CDUP
Net::FTP=GLOB(0x896171c)<<< 250 CDUP command successful
Net::FTP=GLOB(0x896171c)>>> CWD /pages
Net::FTP=GLOB(0x896171c)<<< 250 CWD command successful
Net::FTP=GLOB(0x896171c)>>> ALLO 1379
Net::FTP=GLOB(0x896171c)<<< 200 ALLO command successful
Net::FTP=GLOB(0x896171c)>>> PASV
Net::FTP=GLOB(0x896171c)<<< 227 Entering Passive Mode
(74,208,244,112,208,14).
Net::FTP=GLOB(0x896171c)>>> STOR terminal_4.html
Net::FTP=GLOB(0x896171c)<<< 150 Opening BINARY mode data connection for
terminal_4.html
Net::FTP=GLOB(0x896171c)<<< 226 Transfer complete
$ cat
terminal2.pl
#!/usr/bin/perl -w
use strict;
use 5.010;
use Net::FTP;
use File::Basename;
use Cwd;
use HTML::FromText;
use Text::Template;
use File::Slurp;
## usage needs 1 arg from argv my_ftp
#identity and config
my $ident = 'ident.txt';
my ( $config, $domain );
$config = do($ident);
unless ($config) {
die("read error: $!") if $!;
die("parse error: $@") if $@;
}
$domain = $config->{ $ARGV[0] };
die("unknown domain: $ARGV[0]") unless $domain;
# get local files
my $path = "images1/";
my @files = <$path*>;
print " files are @files\n";
#dial up the server
my $ftp = Net::FTP->new( $domain->{domain}, Debug => 1, Passive => 1 )
or die "Can't connect: $@\n";
$ftp->login( $domain->{username}, $domain->{password} )
or die "Couldn't login\n";
$ftp->binary();
# go to /pages
$ftp->cwd("/pages") or die "Cannot change working directory ",
$ftp->message;
# show working directory
my $dir = cwd;
my $word = basename($dir);
# get files from remote root that end in php:
my @remote_files = $ftp->ls();
# make unique .html choice
my @matching = map /${word}_(\d+)\.html/, @remote_files;
print "matching is @matching\n";
push( @matching, 0 );
@matching = sort { $a <=> $b } @matching;
my $winner = pop @matching;
my $newnum1 = $winner + 1;
my $word2 = "${word}_$newnum1";
print " new word is $word2\n";
my $html_file = "${word2}.html";
print "html file is $html_file\n";
#make directory in images to correspond
$ftp->cdup();
$ftp->cwd("images/")
or die "Cannot change working directory ", $ftp->message;
$ftp->mkdir("${word2}/")
or warn "Cannot create directory ", $ftp->message;
$ftp->cdup();
# create unicode html file
open( my $fh, ">:utf8", $html_file )
or die("Can't open $html_file for writing: $!");
my $input = "template_stuff/hc_input2.txt";
# write in the header
open( my $gh, "<:utf8", $input ) or die("Can't open: $!");
my $template2 = Text::Template->new(SOURCE => $input)
or die "Couldn't construct template: $Text::Template::ERROR";
my %vars = (
title => $word,
headline => 'Helpful Unix Commands',
place => 'Oakland',
css_file => 'rad1.css',
);
my $now_string = localtime;
$vars{date} = $now_string;
my $result = $template2->fill_in(HASH => \%vars);
if (defined $result) { print $fh $result }
else { die "Couldn't fill in template: $Text::Template::ERROR" };
#create template outside loop
my $template = <<'TEMPLATE';
<img src="
http://www.merrillpjensen.com/images/%s"/>
%s
TEMPLATE
#get captions
my $dir2 = "captions/";
my @files2 = <$dir2*>;
@files2 = sort @files2;
print "files are @files2\n";
local $/ = undef;
my $string = read_file($files2[0]);
print "text is $string\n";
my $kludge = text2html(
$string,
urls => 1,
email => 1,
paras => 1,
);
print "text is $kludge\n";
$ftp->cwd("/images/${word2}/") or die "cwd failed $@\n";
# main control
for my $name (@files) {
# captions
my $caption = $kludge;
print "name is $name\n";
my $remote_file = basename($name);
print "remote is $remote_file\n";
$ftp->put( $name, $remote_file ) or die "put failed $!\n";
printf $fh $template, "${word2}/" . $remote_file, $caption;
}
# write in the footer
my $footer = "template_stuff/footer_center.txt";
open( my $hh, "<:utf8", $footer )
or die("Can't open: $!");
while (<$hh>) {
print $fh $_;
}
close $fh;
$ftp->pwd();
$ftp->ls();
$ftp->cdup() or die "cdup failed $@\n";
$ftp->cdup() or die "cdup failed $@\n";
$ftp->cwd("/pages") or die "Cannot change working directory ",
$ftp->message;
$ftp->put($html_file) or die "put failed $@\n";
$
http://merrillpjensen.com/pages/terminal_4.html
I finally kludged this into place. I'm looking to do this in more
generality and breaking this up into pieces that bash move around
instead of my arthritic fingers.
I'm moving away from this particular template to another, and I'd like
to do it in some generality, the type one achieves with bash. There
seems to be some things you can best do with perl and others with unix.
Almost nothing can't be done on a 'puter with the combination used
effectively.
I will be relatively-new to studying servers to the local crowd in
c.u.s.. What I lack in experience I make up for, in some measure, by
reading. I'm in the alpaca book at the beginning of the chapter on
references to subroutines.
So I'm gonna chop that all up and take the first slice where I defined
the variable $kludge. Ben will like that I was being descriptive.
Q1) How would bash determine the highest number .pl in this:
$ ls -l
total 24
drwxr-xr-x 2 fred automation 4096 Sep 18 15:11 captions
-rw-rw-r-- 1 fred automation 793 Aug 26 17:08 ident.txt
drwx------ 2 fred automation 4096 Sep 17 14:54 images1
drwxrwxr-x 2 fred automation 4096 Sep 17 19:49 template_stuff
-rwxr-xr-x 1 fred automation 3664 Sep 18 00:11
terminal1.pl
-rwxr-xr-x 1 fred automation 3664 Sep 18 14:05
terminal2.pl
Thanks for your comment,
--
Cal