Here's the code I used to get the zip on the protected server. Near the bottom, the last subroutine is grab_files is where all the magic happens. In my next post I will give you screen shots from the terminal.
Code:
#!/usr/bin/perl
use strict;
use warnings;
use HTTP::Request::Common qw(GET);
use LWP::UserAgent;
#-----------------------------------------------------------
# obtaining server access by creating a fake browser
#-----------------------------------------------------------
my $ua = new LWP::UserAgent;
$ua->protocols_allowed( [ 'http' ] );
#-----------------------------------------------------------
# methods
#-----------------------------------------------------------
enter_htmlMain();
my ($name, $address) = grab_samples();
enter_samplePage($address);
grab_files($name);
#-----------------------------------------------------------
# subroutines
#-----------------------------------------------------------
# enters the server page with all the sample runs listed
sub enter_htmlMain{
my $url = 'http://server_name/rundb/';
open (OUT, ">", "temp.html") or die $!;
my $user = 'ionuser';
my $pass = 'ionuser';
#sets up request
my $req = GET($url);
$req->authorization_basic($user, $pass);
#do it
my $response = $ua->request($req);
#check and print to file
if ($response->is_error())
{
printf "%s\n", $response->status_line;
print "http request error!\n";
} else {
my $content = $response->content();
print OUT $content;
}
close OUT;
} #end of enter_htmlMain
#-----------------------------------------------------------
# grabs the names and location of the samples currently on
#the server from temp.html and prints them for user selection
#-----------------------------------------------------------
sub grab_samples{
my %sample;
my $i = 1;
open (IN, "<", "temp.html");
while (<IN>){
if ($_=~/<a href=\"(\/output\/Home\/.*\.php)\"/){
my $holder = $1;
my $sample_name;
my $address = "http://server_name$holder";
if ($holder=~/\/output\/Home\/(.*)\//){$sample_name = $1;}
my $info = "$sample_name\t$address";
print "$i\t$sample_name\n";
$sample{$i} = $info;
$i++;
} #end of original 'if' statement
} #end of 'while' loop
close IN;
print "\n\nPlease select sample.\t";
my $input = <>;
chomp $input;
my @temp = split(/\t/,$sample{$input});
my $n = $temp[0];
my $a = $temp[1];
return ($n, $a);
#remove temp.html
my $cmd = "rm temp.html";
system ($cmd);
if ($?) {die "command: $cmd failed\n"};
} # end of grab_samples
#-----------------------------------------------------------
# copies the html page from the sample of intrest to temp.html
#-----------------------------------------------------------
sub enter_samplePage{
my @destination = @_;
my $url = $destination[0];
open (OUT, ">", "temp.html") or die $!;
my $user = 'ionuser';
my $pass = 'ionuser';
#sets up request
my $req = GET($url);
$req->authorization_basic($user, $pass);
#do it
my $response = $ua->request($req);
#check and print to file
if ($response->is_error())
{
printf "%s\n", $response->status_line;
print "http request error!\n";
} else {
my $content = $response->content();
print OUT $content;
}
close OUT;
} #end of enter_samplePage
#-----------------------------------------------------------
# grabs the barcode sff files and downloads them from the server
#-----------------------------------------------------------
sub grab_files{
my @name = @_;
my $barcode_sff;
open (IN, "<", "temp.html");
my @file = <IN>;
close IN;
foreach my $j (@file){
if ($j=~/\(BAI\).*href\=\'(.*\.barcode\.sff\.zip)\'/){$barcode_sff = $1;}
}
#remove temp.html
my $cmd = "rm temp.html";
system ($cmd);
if ($?) {die "command: $cmd failed\n"};
#downloading .zip file
my $barcode_sff_url = "http://server_name/output/Home/$name[0]/$barcode_sff";
open (OUT, ">", $barcode_sff) or die $!;
my $user = 'ionuser';
my $pass = 'ionuser';
#sets up request
my $req = GET($barcode_sff_url);
$req->authorization_basic($user, $pass);
#do it
my $response = $ua->request($req);
#check and print to file
if ($response->is_error())
{
printf "%s\n", $response->status_line;
print "http request error!\n";
} else {
my $content = $response->content();
print OUT $content;
}
close OUT;
#change permissions on .zip
$cmd = "chmod 775 $barcode_sff";
system ($cmd);
if ($?) {die "command: $cmd failed\n"};
#unzip barcode.sff.zip
$cmd = "unzip $barcode_sff";
system ($cmd);
if ($?) {die "command: $cmd failed\n"};
#remove barcode.sff.zip
$cmd = "rm $barcode_sff";
system ($cmd);
if ($?) {die "command: $cmd failed\n"};
} #end of grab_files
---------- Post updated at 02:20 PM ---------- Previous update was at 02:03 PM ----------
I don't have the images online. Is there a way I can sent you an email? or is there some other method I could get these images to you?
Last edited by Scrutinizer; 06-09-2012 at 03:00 AM..
Reason: code tags
I am bit unclear of how Linux was set in the real world, please advise me how it's supposed to be.
When I log in as root and do a ls -l, I find: /boot, /, /var, /usr, /tmp, /home, /u01, /u02, /u03 and of of this partition is owned by root and the group also belong to root. Is that the way it's... (1 Reply)
Hi,
I don't know how the owner & group of a login file in redhat linux 7.2 changed to bache like,
-rwxr-xr-x 1 bache bache 17740 Jun 20 02:05 login
I am trying to change the owner and group to root by using
#chown root login
#chgrp root login
But i am getting the error ... (7 Replies)
hello
I search a script (ksh for Aix 5.3) to save all permissions, groups and owner for all files. Because we work much to change it, and a mystake ......!
So i want execute this script to save/ execute permissions for all files.
If you have this script, thank you for your help ;)
best... (2 Replies)
How to set the name of the group and the owner while creation of the file?
-rwxrwxr-x 1 root sys 1202 Dec 5 2002 abc.awk
like here i need to set the name of root and sys to xxx xxx
Any help is appreciated.
Thanks. (2 Replies)
Hi,
We have almost 45,000 data files created by a script daily. The file names are of format-ODS.POS.<pharmacyid>.<table name>.<timestamp>.dat. There will be one data file like this for each pharmacy and each table.(Totally around 45,000)
The requirement is to create a control file for each... (2 Replies)
How would I find out who the group openers is of a file? For example:
> ls -l myfile
-rwxr-xr-x 1 myronp hawks 20125 Oct 20 20:50 myfile
How do I return just hawks. I could do this with a series of cut or awk, but is there a more direct way.
The ls -g is better, but still... (1 Reply)
If I have to identify the group owner of an AIX group, what is the command to be used. Example: there is an mqadm group, how do I find the owner of this group?
Please help. (6 Replies)
Dears
it is normal that the below binaries stay without any owner and group
I have checked it in many servers and the like the below
/usr/lpp/bos.net/inst_root/etc/ipsec# ls -lrt
total 248
-r-xr-xr-x 1 987 987 13589 Jun 29 2005 default_group
-r-xr-xr-x ... (5 Replies)
Hi Team,
Am a newbie to Unix. As I would like to see the Server Name,Owner Name ( not numeric form), Group Name ( not numeric ID), ROOT path.
I would like to send this list as an attachment to my personal mail. Can any one please help me out to to resolve this .
Here is the sample result... (6 Replies)