Showing posts with label Perl. Show all posts
Showing posts with label Perl. Show all posts
2007/12/03
one line perl script - monitoring file increase speed
perl -e '$l=0;while(1) { sleep 1; $m=`du -k`; $m =~ s/^\s+//; $m =~ s/\s+.\n//; @dt = localtime(time); print "". ($dt[5]+1900) ."/". ($dt[4]+1) ."/$dt[3] $dt[2]:$dt[1]:$dt[0] ". ($m-$l) ."/$m k\n"; $l=$m;}'
one line perl script - monitoring file increase speed
perl -e '$l=0;while(1) { sleep 1; chop($m=`du -k`); $m =~ s/^\s+//; $m =~ s/\s+$//; print join(" ",localtime(time)) . " " .
($m-$l). "/$m (k)\n"; $l=$m;}'
($m-$l). "/$m (k)\n"; $l=$m;}'
2007/08/29
renameall utitlity
renameall.bat
renameall.pl
@echo off
verify errors 2>nul
setlocal enableextensions
if errorlevel 1 echo unable to enable extensions
set USR_LOCAL_BIN=F:\usr\local\bin
perl %USR_LOCAL_BIN%\renameall2.pl %*
endlocal
echo on
renameall.pl
#!/bin/perl
#
#renameall.pl
#
# Syntax: renameall -uls ([*][0-9A-Za-z]+){1,3} ([*][0-9A-Za-z]+){1,3}
# Example: renameall *.* *.*
use strict;
use warnings;
#---------------------------------
# constant
my $TRUE = -1;
my $FALSE = 0;
my $SYNTAX = "Syntax: renameall([*][0-9A-Za-z]+){1,3} ([*][0-9A-Za-z]+){1,3}";
my $OPT_UPPER = 1 << 2;
my $OPT_LOWER = 1 << 1;
my $OPT_SEMULATE = 1;
#---------------------------------
# parameter
#my $opt_semulate = $FALSE;
my $options = 0;
my $searchstr = '';
my $replacestr = '';
my @replacestrarr = {};
my $replacestrarrcnt = 0;
my $i;
my $j;
my $paramcnt;
for ($i = 0, $paramcnt = 0; $i < $#ARGV + 1; $i ++) {
#printf ("\$ARGV[$i]=$ARGV[$i]\n");
if (substr($ARGV[$i], 0, 1) eq '-') {
#printf ("option $ARGV[$i]\n");
for ($j = 1; $j < length($ARGV[$i]); $j ++) {
my $opt_char = substr($ARGV[$i], $j, 1);
if ($opt_char eq 's' || $ARGV[$i] eq '--semulate') {
#$opt_semulate = $TRUE;
$options |= $OPT_SEMULATE;
} elsif ($opt_char eq 'l' || $ARGV[$i] eq '--lower') {
$options |= $OPT_LOWER;
} elsif ($opt_char eq 'u' || $ARGV[$i] eq '--upper') {
$options |= $OPT_UPPER;
}
}
} else {
if ($paramcnt == 0) {
$searchstr = $ARGV[$i];
#printf ("\$searchstr = $ARGV[$i]\n");
$searchstr =~ s/([\.\[\]\(\)\/])/\\$1/g;
$searchstr =~ s/\*/(.*)/g;
#my @searcharr = split(/\*/,$searchstr);
#my $replacestrarrcnt = $#searcharr;# - 1;
} elsif ($paramcnt == 1) {
$replacestr = $ARGV[$i];
#printf ("\$replacestr = $ARGV[$i]\n");
#$replacestr =~ s/\./\\\./g;
#$replacestr =~ s/\*//;
@replacestrarr = split (/\*/, $replacestr);
$replacestrarrcnt = $#replacestrarr;
$replacestr =~ m/.$/;
if ($& eq '*') {
$replacestrarrcnt++;
}
$i = 1;
#while ($replacestr =~ m/\*/) {
# $replacestr =~ s/\*/\\$i/;
#}
}
$paramcnt ++;
}
}
printf ("\$options: %08.0b ---- -ULS\n", $options);
if ($paramcnt < 2) {
die "insufficient parameters.\n$SYNTAX\n";
}
# deal with the pattern that search arr > replace arr
for ($i = 0; $i < 10; $i ++) {
push (@replacestrarr, '');
}
#print (join ('*',@replacestrarr)."\n");
print ("internal pattern: \$searchstr=$searchstr;\$replacestr=$replacestr;\n");
#----------------------------------
# ls dir
opendir(THEDIR, ".");
my @selected=grep(/^$searchstr$/, readdir THEDIR);
closedir(THEDIR);
#print (join("\n",@selected)."\n");
if ($#selected == -1) {
die "nothing found.\n";
}
#----------------------------------
# rename the file one by one
foreach my $oldfilename (@selected) {
# convert old filename to new filename
my $newfilename = $oldfilename;
#print ($replacestrarrcnt);
if ($replacestrarrcnt == 0) {
$newfilename =~ s/$searchstr/$replacestrarr[0]/g;
} elsif ($replacestrarrcnt == 1) {
$newfilename =~ s/$searchstr/$replacestrarr[0]$1$replacestrarr[1]/g;
} elsif ($replacestrarrcnt == 2) {
$newfilename =~ s/$searchstr/$replacestrarr[0]$1$replacestrarr[1]$2$replacestrarr[2]/g;
} elsif ($replacestrarrcnt == 3) {
$newfilename =~ s/$searchstr/$replacestrarr[0]$1$replacestrarr[1]$2$replacestrarr[2]$3$replacestrarr[3]/g;
} else {
die "unsupported pattern $replacestr : too much '*' .\n";
}
if ($options & $OPT_LOWER) {
#printf ("lower");
$newfilename = lc ($newfilename);
} elsif ($options & $OPT_UPPER) {
#printf ("upper");
$newfilename = uc ($newfilename);
}
#$oldfilename =~ s/([\.\[\]\(\)\/])/\\$1/g;
printf ("$oldfilename\t-> $newfilename\n");
if (!($options & $OPT_SEMULATE)) {
#printf ("rename ($oldfilename, $newfilename) || die");
if (-e $newfilename) {
printf ("the file rename to '$newfilename' is already exists. overwrite it (Y/N) ");
while (<>) {
if (m/^[Yy]/) {
rename ($oldfilename, $newfilename) || die;
}
}
}
}
}
2007/08/06
perl CPAM install ReadLine::Gnu
[root@test pkg]# perl pmlist.pl
IO::Tty -- 1.07
Perl -- 5.8.0
Confirm the error message
I resolved it finally with
IO::Tty -- 1.07
Perl -- 5.8.0
pmlist.pl
#!/usr/bin/perl
use ExtUtils::Installed;
my $instmod = ExtUtils::Installed->new();
foreach my $module ($instmod->modules()) {
my $version = $instmod->version($module) || "???";
print "$module -- $version\n";
}
[root@test pkg]# perl -MCPAN -e shell
cpan shell -- CPAN exploration and modules installation (v1.61)
ReadLine support available (try 'install Bundle::CPAN')
cpan> install Term::ReadLine::Gnu
Running install for module Term::ReadLine::Gnu
Running make for H/HA/HAYASHI/Term-ReadLine-Gnu-1.16.tar.gz
CPAN: Digest::MD5 loaded ok
Checksum for /root/.cpan/sources/authors/id/H/HA/HAYASHI/Term-ReadLine-Gnu-1.16.tar.gz ok
Scanning cache /root/.cpan/build for sizes
Term-ReadLine-Gnu-1.16/
Term-ReadLine-Gnu-1.16/eg/
Term-ReadLine-Gnu-1.16/eg/fileman
Term-ReadLine-Gnu-1.16/eg/perlsh
Term-ReadLine-Gnu-1.16/eg/pftp
Term-ReadLine-Gnu-1.16/eg/ptksh+
Term-ReadLine-Gnu-1.16/Gnu/
Term-ReadLine-Gnu-1.16/Gnu/euc_jp.pm
Term-ReadLine-Gnu-1.16/Gnu/XS.pm
Term-ReadLine-Gnu-1.16/Gnu.pm
Term-ReadLine-Gnu-1.16/Gnu.xs
Term-ReadLine-Gnu-1.16/INSTALL
Term-ReadLine-Gnu-1.16/Makefile.PL
Term-ReadLine-Gnu-1.16/MANIFEST
Term-ReadLine-Gnu-1.16/META.yml
Term-ReadLine-Gnu-1.16/ppport.h
Term-ReadLine-Gnu-1.16/README
Term-ReadLine-Gnu-1.16/t/
Term-ReadLine-Gnu-1.16/t/button.pl
Term-ReadLine-Gnu-1.16/t/callback.t
Term-ReadLine-Gnu-1.16/t/comptest/
Term-ReadLine-Gnu-1.16/t/comptest/0123
Term-ReadLine-Gnu-1.16/t/comptest/012345
Term-ReadLine-Gnu-1.16/t/comptest/023456
Term-ReadLine-Gnu-1.16/t/comptest/a_b
Term-ReadLine-Gnu-1.16/t/comptest/README
Term-ReadLine-Gnu-1.16/t/history.t
Term-ReadLine-Gnu-1.16/t/inputrc
Term-ReadLine-Gnu-1.16/t/readline.t
Term-ReadLine-Gnu-1.16/typemap
Removing previously used /root/.cpan/build/Term-ReadLine-Gnu-1.16
CPAN.pm: Going to build H/HA/HAYASHI/Term-ReadLine-Gnu-1.16.tar.gz
Found `/usr/lib/libtermcap.a'.
gcc -D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm -DHAVE_STRING_H rlver.c -o rlver -L/usr/local/lib -lreadline -ltermcap
It seems that you have the GNU Readline Library version 4.3.
Checking if your kit is complete...
Looks good
Writing Makefile for Term::ReadLine::Gnu
cp Gnu.pm blib/lib/Term/ReadLine/Gnu.pm
cp Gnu/XS.pm blib/lib/Term/ReadLine/Gnu/XS.pm
AutoSplitting blib/lib/Term/ReadLine/Gnu/XS.pm (blib/lib/auto/Term/ReadLine/Gnu/XS)
cp Gnu/euc_jp.pm blib/lib/Term/ReadLine/Gnu/euc_jp.pm
/usr/bin/perl /usr/lib/perl5/5.8.0/ExtUtils/xsubpp -typemap /usr/lib/perl5/5.8.0/ExtUtils/typemap -typemap typemap Gnu.xs > Gnu.xsc && mv Gnu.xsc Gnu.c
gcc -c -D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm -O2 -g -pipe -march=i386 -mcpu=i686 -DVERSION=\"1.16\" -DXS_VERSION=\"1.16\" -fPIC "-I/usr/lib/perl5/5.8.0/i386-linux-thread-multi/CORE" -DHAVE_STRING_H Gnu.c
Running Mkbootstrap for Term::ReadLine::Gnu ()
chmod 644 Gnu.bs
rm -f blib/arch/auto/Term/ReadLine/Gnu/Gnu.so
LD_RUN_PATH="/usr/lib:/lib" gcc -shared -L/usr/local/lib Gnu.o -o blib/arch/auto/Term/ReadLine/Gnu/Gnu.so -lreadline -ltermcap
chmod 755 blib/arch/auto/Term/ReadLine/Gnu/Gnu.so
cp Gnu.bs blib/arch/auto/Term/ReadLine/Gnu/Gnu.bs
chmod 644 blib/arch/auto/Term/ReadLine/Gnu/Gnu.bs
Manifying blib/man3/Term::ReadLine::Gnu.3pm
/usr/bin/make -- OK
Running make test
PERL_DL_NONLAZY=1 /usr/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/callback....ok
4/7 skipped: since Tk is not installed.
t/history.....FAILED tests 73-74
Failed 2/82 tests, 97.56% okay
t/readline....ok Try `/usr/bin/perl -Mblib t/readline.t verbose', if you will.
t/readline....ok
Failed Test Stat Wstat Total Fail Failed List of Failed
-------------------------------------------------------------------------------
t/history.t 82 2 2.44% 73-74
4 subtests skipped.
Failed 1/3 test scripts, 66.67% okay. 2/193 subtests failed, 98.96% okay.
make: *** [test_dynamic] エラー 29
/usr/bin/make test -- NOT OK
Running make install
make test had returned bad status, won't install without force
cpan> quit
Lockfile removed.
Confirm the error message
[root@test Term-ReadLine-Gnu-1.16]# pwd
/root/.cpan/build/Term-ReadLine-Gnu-1.16
I resolved it finally with
force install ...
uniread - the best oracle command mate
uniread adds readline (line editing, command history, etc.) support to any
existing interactive command-line program. You can use this to add support
to annoying programs which do not provide it built-in (a good example is
Oracle's sqlplus, or jython) or to easily add it to your own programs.
To build this distribution, run:
uniread requires:
- GNU readline
http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html
- Term::ReadLine::Gnu
http://search.cpan.org/dist/Term-ReadLine-Gnu/
- IO::Tty
http://search.cpan.org/dist/IO-Tty/
or http://sourceforge.net/projects/expectperl
The latter two can be installed using the CPAN shell. Run:
-----
By me:
Add a command to .bash_profile/profile will help common user to uniread
existing interactive command-line program. You can use this to add support
to annoying programs which do not provide it built-in (a good example is
Oracle's sqlplus, or jython) or to easily add it to your own programs.
To build this distribution, run:
perl Makefile.PL
make
make install
uniread requires:
- GNU readline
http://cnswww.cns.cwru.edu/php/chet/readline/rltop.html
- Term::ReadLine::Gnu
http://search.cpan.org/dist/Term-ReadLine-Gnu/
- IO::Tty
http://search.cpan.org/dist/IO-Tty/
or http://sourceforge.net/projects/expectperl
The latter two can be installed using the CPAN shell. Run:
perl -MCPAN -e shell
install Term::ReadLine::Gnu
install IO::Tty
-----
By me:
Add a command to .bash_profile/profile will help common user to uniread
# proxy
export http_proxy=http://proxy:8080/
export ftp_proxy=http://proxy:8080/
# initialize CPAN, just press enter except download site
perl -MCPAN -e shell
# install the pre-required modules, force for 86-64
perl -MCPAN -e shell << __EOF__
force install Term::ReadLine::Gnu
install IO::Tty
__EOF__
# copy and install uniread package
cd ~
[ ! -d pkg ] && mkdir pkg
pushd pkg
cp -a ~oracle/work/fyang/ofpkg/uniread*.tar.gz .
tar -zxvf uniread*.tar.gz
cd uniread*
perl Makefile.PL
make install
popd
# profile
cat >> /etc/profile << __EOF__
alias ufsqlplus="echo enter popd to return to original dir. ; pushd ~oracle/work/fyang ; uniread --quiet sqlplus "
alias sqlplusuf="echo enter popd to return to original dir. ; pushd ~oracle/work/fyang ; uniread --quiet sqlplus "
alias usqlplus="uniread --quiet sqlplus "
alias sqlplusu="uniread --quiet sqlplus "
__EOF__
Subscribe to:
Posts (Atom)