[32611] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 3884 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 22 09:09:23 2013

Date: Fri, 22 Feb 2013 06:09:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 22 Feb 2013     Volume: 11 Number: 3884

Today's topics:
        Apache 2.2 & (Fast?) CGI running under separate uid's <oneingray@gmail.com>
    Re: Is there a shorter, more elegant way to write this  <tzz@lifelogs.com>
    Re: Is there a shorter, more elegant way to write this  <tzz@lifelogs.com>
    Re: system commands exit 1 [corrected] <rocallen@cisco.com>
    Re: system commands exit 1 [corrected] <ben@morrow.me.uk>
    Re: system commands exit 1 [corrected] <uri@stemsystems.com>
    Re: system commands exit 1 [corrected] <vilain@NOspamcop.net>
    Re: system commands exit 1 [corrected] <rocallen@cisco.com>
        system commands exit 1 <rocallen@cisco.com>
    Re: system commands exit 1 <ben@morrow.me.uk>
    Re: system commands exit 1 <rocallen@cisco.com>
    Re: system commands exit 1 <cwilbur@chromatico.net>
    Re: system commands exit 1 <ben@morrow.me.uk>
    Re: system commands exit 1 <rvtol+usenet@xs4all.nl>
    Re: system commands exit 1 (Seymour J.)
    Re: system commands exit 1 <ben@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Fri, 22 Feb 2013 12:53:52 +0000
From: Ivan Shmakov <oneingray@gmail.com>
Subject: Apache 2.2 & (Fast?) CGI running under separate uid's
Message-Id: <87ip5kcxwf.fsf_-_@violet.siamics.net>

>>>>> Ben Morrow <ben@morrow.me.uk> writes:
>>>>> Quoth Ivan Shmakov <oneingray@gmail.com>:

 > [f'ups set to clpmisc]

	[Disregarded, and dropped news:comp.lang.perl.misc from
	Followup-To:, as my questions below are little related to Perl.]

 >> Is there an easy way to run Perl CGI::Simple-based code interfacing
 >> Apache 2.2, under a separate UID?  (Apart of suexec, that is, which,
 >> depending on the circumstances, may or may not constitute "an easy
 >> way.")

	To clarify: my issue with Apache's mod_suexec is that (as of
	2.2) I cannot use configure SuexecUserGroup within, say, a
	<Directory /> block.  Which means that I have to introduce a
	<VirtualHost /> whenever I want to run a new Web application
	under a new UID.

 >> I'd like to make the code "persistent" as well, but it's not a hard
 >> requirement for now.

[...]

 > Are you considering changing the code which calls CGI::Simple, or are
 > you trying to avoid that?

	FWIW, wrapping a CGI::Simple code into a FCGI loop doesn't seem
	like a big deal.  Like (untested):

    ## Was:

    my $o
        = \*STDOUT;
    my $q
        = CGI::Simple->new ()
        or die ();
    ## ...
    ## FIXME: and what about the encoding?
    $o->print ($q->header  ("-type"     => "application/xhtml+xml",
                            @more_headers));
    binmode ($o);
    $xml->setEncoding ("utf-8");
    $xml->toFH ($o, 0);


    ## Becomes:

    my $sock
        = FCGI::OpenSocket ($sock_fn, 7);
    die ()
        if ($sock < 0);
    my $o
        = \*STDOUT;
    binmode ($o);
    my $rq
        = FCGI::Request (\*STDIN, $o, \*STDERR, \%ENV, $sock)
        or die ();
    ## NB: a never-ending loop?
    while ($rq->Accept () >= 0) {
        my $q
            = CGI::Simple->new ()
            or die ();
        ## ...
        ## FIXME: and what about the encoding?
        $o->print ($q->header  ("-type"     => "application/xhtml+xml",
                                @more_headers));
        $xml->setEncoding ("utf-8");
        $xml->toFH ($o, 0);
        $rq->Finish ();
    }

	Obviously, any "early exit" locations should be tweaked as well,
	and the state cleaned up.  (Most of the state should be GC'ed by
	the Perl system itself, however, should it be associated with
	"my" variables.)

[...]

 >> The FCGI Perl module and mod_fcgi look like a bit more promising a
 >> couple, as they seem to support AF_UNIX sockets "out of box."  Are
 >> there any issues likely to arise with them?

 > IME FastCGI with FCGI.pm is extremely reliable.

	ACK, thanks!

 > I use it either via Plack or via Catalyst (which uses Plack these
 > days).

	I believe that the only proper way to utilize a separate UID for
	a Web application is to start it separately from the HTTP server
	(say, with its own script run during the system's boot up), with
	the server communicating the application via a Unix socket.

	Then, either the starting script, a helper, or the Web
	application itself is responsible for dropping the root
	privileges.  (Just as in the case of the HTTP server itself.)

	The use of Unix sockets allows for the Unix filesystem access
	control to be utilized, thus ensuring that the HTTP server
	passes the (potentially sensitive) information contained within
	the HTTP request to the designated application.  (It is much
	harder to maintain this level of security with TCP/IP sockets.)

	Unfortunately, AIUI, the mod_fcgid (as available for Apache 2.2)
	insists on starting the Fast CGI code by itself, thus requiring
	a set-UID wrapper to switch the UID.

	OTOH, mod_proxy_fcgi, while requiring for the Fast CGI code to
	be started separately, insists on using TCP/IP sockets.

	Thus, as it seems, I'm having no luck with Apache either way.

	Lighttpd, however, can be configured in such a way.  Consider,
	e. g.:

--cut: http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModFastCGI --
  fastcgi.server = ( ".php" =>
    (( "socket" => "/tmp/php-fastcgi.socket",
        "bin-path" => "/usr/local/bin/php"
    ))
  )
--cut: http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModFastCGI --

	(though, obviously, "bin-path" is an extra here.)

	Unfortunately, I'm somewhat concerned with the (possible) lack
	of features in Lighttpd that I may wish to utilize, one of them
	being the Kerberos authentication support, yet to appear in its
	stable version.

[...]

 >> PS.  It's possible that I'll consider switching from Apache to
 >> Lighttpd later, so I wonder if there could be any "CGI-like"
 >> interfaces implemented for both of these HTTP servers?

 > Both Lighty and nginx (which you should consider as an alternative to
 > lighty)

	Perhaps, though at the first glance, Lighttpd looked a bit
	easier to configure.  (Why, my ~/.lighttpd/lighttpd.conf, which
	I used to gain some familiarity with the server, and its CGI
	features, is only 27 lines long, sans the blank lines and
	comments.  IIRC, my ~/.nginx/nginx.conf was a few times larger.)

 > have good FastCGI support.  They also both have good HTTP proxy
 > support, which is quite a common way to run persistent web apps these
 > days; basically you use HTTP as the app-to-server protocol as well as
 > the server-to-client protocol.

	There seem to be a couple of drawbacks in using HTTP for server
	to application communication.  Namely:

	* I know of no standard way to pass the authentication
	  credentials (either HTTP "plain" or Kerberos), or X.509
	  certificate down such a proxy chain;

	* as long as Apache is concerned, I expect it to require the use
	  of TCP/IP sockets for such communication (while using Unix
	  ones would arguably be more secure.)

	Unless these issues are in fact easy to resolve, I wouldn't
	really consider HTTP as a substitute for (whatever) CGI.

[...]

-- 
FSF associate member #7257


------------------------------

Date: Thu, 21 Feb 2013 11:35:28 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Is there a shorter, more elegant way to write this deep hash lookup statement
Message-Id: <87sj4pvd4f.fsf@lifelogs.com>

On Sat, 16 Feb 2013 18:16:33 -0600 Ignoramus329 <ignoramus329@NOSPAM.329.invalid> wrote: 

I> As I always say 'use strict; use warnings', I have this statement in my program:
I>   $is_freight = 1
I>     if $ebay_record
I>       && $ebay_record->{ShippingDetails}
I>       && $ebay_record->{ShippingDetails}->{ShippingServiceOptions}
I>       && $ebay_record->{ShippingDetails}->{ShippingServiceOptions}->{ShippingService}
I>       && $ebay_record->{ShippingDetails}->{ShippingServiceOptions}->{ShippingService} eq 'Freight';

I> This is a correct statement and it does not give errors or warnings,
I> however, I would like to know if I can write it in a shorter way. 

I have a function to do this, which recursively searches a hashref.  It
has some array search logic as well; just remove the second part if you
don't want that (I needed it for parsing some XML data).  You could use
Data::Match instead, but it's really not a difficult task either way,
and I like my interface better.

You call it like this for your case:

hashref_search($ref, qw/ShippingDetails ShippingServiceOptions ShippingService/);

and just check that the return is defined and equal to 'Freight'.

Hope that helps...
Ted

#+begin_src perl
sub hashref_search
{
 my $ref = shift @_;
 my $k = shift @_;
 if (ref $ref eq 'HASH' && exists $ref->{$k})
 {
  if (scalar @_ > 0) # dig further
  {
   return hashref_search($ref->{$k}, @_);
  }
  else
  {
   return $ref->{$k};
  }
 }

 if (ref $ref eq 'ARRAY' && ref $k eq 'HASH') # search an array
 {
  foreach my $item (@$ref)
  {
   foreach my $probe (keys %$k)
   {
    if (ref $item eq 'HASH' &&
        exists $item->{$probe})
    {
     # if the value is undef...
     return $item unless defined $k->{$probe};
     # or it matches the probe
     return $item if $item->{$probe} eq $k->{$probe};
    }
   }
  }
 }

 return undef;
}

#+end_src


------------------------------

Date: Thu, 21 Feb 2013 11:37:10 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Is there a shorter, more elegant way to write this deep hash lookup statement
Message-Id: <87obfdvd1l.fsf@lifelogs.com>

On Sun, 17 Feb 2013 12:18:47 +0100 "Dr.Ruud" <rvtol+usenet@xs4all.nl> wrote: 

R> Or wait for the &-> operator:

R> $is_freight = $ebay_row&->{ShippingDetails}&->{ShippingServiceOptions}&->{ShippingService} eq 'Freight';

Oh, that's ugly.

Ted


------------------------------

Date: Wed, 20 Feb 2013 14:11:02 -0500
From: "R. Allen" <rocallen@cisco.com>
Subject: Re: system commands exit 1 [corrected]
Message-Id: <1361387462.774567@rcdn-nntpcache-1>

Sorry gurus,

 > I cannot seem to figure out why these commands are returning 1;
 >
 > wget returns 1 with "bad file descriptor"
 > curl returns 1 with " ENOTTY (Inappropriate ioctl for device)"
 >
 > Any assistance would be appreciated.

Here's the actual code, and how Im running it:
perl -d webdavcheck http://[snip].cisco.com:[snip]/[snip]/[snip]/ > log.txt
 >cat log.txt
Bad file descriptor0
Bad file descriptorInappropriate ioctl for device


#!/usr/bin/perl

use strict;

my $url = $ARGV[0];
my $now = `date +%s`;
my $differential='360';
my $transitfile = "wdtimekeeper";

my $cleanup = system("unlink $transitfile");
if (! $cleanup) {
         print $!;
}

my $wget=system("wget $url$transitfile");
print "$wget\n";
if (! $wget)    {
         print $!;
}

my $laststamp = `cat $transitfile`;

open FH1,"+>","$transitfile" || print "cant\n";
print FH1 $now;
close FH1;

my $curl = system("curl -k -T $transitfile $url");
#system("curl -d -k -T $transitfile $url");
if (! $curl)    {
         print $!;
}
my $a = $now - $differential;

if ($a > $laststamp)    {
         exit 1;
}












On 2/20/2013 1:28 PM, R. Allen wrote:
> Hello list,
>
> I cannot seem to figure out why theses commands are returning 1;
>
> wget returns 1 with "bad file descriptor"
> curl returns 1 with " ENOTTY (Inappropriate ioctl for device)"
>
> Any assistance would be appreciated.
>
> #!/usr/bin/perl
>
> use strict;
>
> my $url = $ARGV[0];
> my $now = `date +%s`;
> my $differential='360';
> my $transitfile = "wdtimekeeper";
>
> my $cleanup = system("unlink $transitfile");
> if (! $cleanup) {
>          print "no file\n";
> }
>
> my $wget=system("wget $url$transitfile");
> print "$wget\n";
> if (! $wget)    {
>          exit 1;
> }
>
> my $laststamp = `cat $transitfile`;
>
> open FH1,"+>","$transitfile" || print "cant\n";
> print FH1 $now;
> close FH1;
>
> my $curl = system("curl -k -T $transitfile $url");
> #system("curl -d -k -T $transitfile $url");
> if (! $curl)    {
>          print "1\n";
> }
> my $a = $now - $differential;
>
> if ($a > $laststamp)    {
>          exit 1;
> }



------------------------------

Date: Wed, 20 Feb 2013 21:05:32 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: system commands exit 1 [corrected]
Message-Id: <sdqfv9-s02.ln1@anubis.morrow.me.uk>


Quoth "R. Allen" <rocallen@cisco.com>:
> Sorry gurus,
> 
>  > I cannot seem to figure out why these commands are returning 1;
>  >
>  > wget returns 1 with "bad file descriptor"
>  > curl returns 1 with " ENOTTY (Inappropriate ioctl for device)"
>  >
>  > Any assistance would be appreciated.
> 
> Here's the actual code, and how Im running it:
> perl -d webdavcheck http://[snip].cisco.com:[snip]/[snip]/[snip]/ > log.txt
>  >cat log.txt
> Bad file descriptor0
> Bad file descriptorInappropriate ioctl for device
> 
> 
> #!/usr/bin/perl
> 
> use strict;

    use warnings;

> my $url = $ARGV[0];
> my $now = `date +%s`;

Perl also has time() built in. If you want a formatted time, you can use
localtime() or gmtime() and strftime() from the POSIX module.

> my $differential='360';

This is a number. Why are you quoting it?

> my $transitfile = "wdtimekeeper";
> 
> my $cleanup = system("unlink $transitfile");
> if (! $cleanup) {
>          print $!;

system returns 0 on success (as I said). 0 is false, so this will print
$! if unlink(1) *succeeds*. $! doesn't hold anything useful if a system
call has not just failed, so getting a random error message doesn't
indicate anything is wrong. (Probably the 'Bad file descriptor' comes
from a system call system() made internally.)

If system() had actually failed, printing the error but then carrying on
anyway is not very sensible. You probably want to die(). If you use the
'autodie' module it can automatically print an error and exit when
something fails; it doesn't do so for system() by default, so you would
need to read its documentation.

> }
> 
> my $wget=system("wget $url$transitfile");

You should get into the habit of using the multi-argument form of
system(), since it avoids problems with characters treated as special by
the shell.

    my $wget = system("wget", "$url$transitfile");

> print "$wget\n";

This prints "0", so wget also succeeded.

> if (! $wget)    {
>          print $!;

This prints 'Bad file descriptor' for the same reason as above.

> }
> 
> my $laststamp = `cat $transitfile`;

That's an extremely roundabout way of reading a file. The usual idiom in
Perl is

    my $laststamp = do {
        local $/;
        open my $FH, "<", $transitfile
            or die "can't read '$transitfile'";
        <$FH>;
    };

though that requires a bit of Perl to understand.

    perldoc perlsyn     (for do {})
    perldoc perlvar     (for $/)
    perldoc -f local
    perldoc -f open
    perldoc perlop      (for <>)

Alternatively you can use the File::Slurp module, though you will need
to learn how to install modules for that.

> 
> open FH1,"+>","$transitfile" || print "cant\n";

Why are you opening this file read-write?

You should keep your filehandles in variables:

    open my $FH1, ...;

> print FH1 $now;
> close FH1;

If you wrote to a file you should check the return value of close().
(Checking the return value of print is neither necessary nor
sufficient.) autodie will do this for you.

> my $curl = system("curl -k -T $transitfile $url");

    my $curl = system("curl", "-k", "-T", $transitfile, $url);

> #system("curl -d -k -T $transitfile $url");
> if (! $curl)    {
>          print $!;

And again you get a random error message, this time a different one.
There is nothing going wrong here.

Ben



------------------------------

Date: Thu, 21 Feb 2013 02:55:25 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: system commands exit 1 [corrected]
Message-Id: <87ppzuhziq.fsf@stemsystems.com>

>>>>> "RA" == R Allen <rocallen@cisco.com> writes:


i won't address how or why your system calls are failing. i will ask WHY
you are forking out for stuff perl does easily?


  RA> my $url = $ARGV[0];
  RA> my $now = `date +%s`;

POSIX::strftime does all that date does

  RA> my $differential='360';
  RA> my $transitfile = "wdtimekeeper";

  RA> my $cleanup = system("unlink $transitfile");

perl has unlink builtin

  RA> if (! $cleanup) {
  RA>         print $!;
  RA> }

  RA> my $wget=system("wget $url$transitfile");

wget is done in perl with LWP.

  RA> print "$wget\n";
  RA> if (! $wget)    {
  RA>         print $!;
  RA> }

  RA> my $laststamp = `cat $transitfile`;

useless use of cat in perl! several very easy and fast ways to read in a
file. my File::Slurp::read_file is easy, fast and very popular.

  RA> open FH1,"+>","$transitfile" || print "cant\n";
  RA> print FH1 $now;
  RA> close FH1;

the same module has write_file. why do you open with +> when you are
just writing a fresh timestamp?

  RA> my $curl = system("curl -k -T $transitfile $url");

from what i know about curl, LWP can do that.

so if you stick with perl your code would be clearer, shorter, faster
and have fewer issues with system and backticks (in fact no issues).

uri


------------------------------

Date: Thu, 21 Feb 2013 00:38:41 -0800
From: Michael Vilain <vilain@NOspamcop.net>
Subject: Re: system commands exit 1 [corrected]
Message-Id: <vilain-876350.00384121022013@news.individual.net>

In article <87ppzuhziq.fsf@stemsystems.com>,
 Uri Guttman <uri@stemsystems.com> wrote:

> >>>>> "RA" == R Allen <rocallen@cisco.com> writes:
> 
> 
> i won't address how or why your system calls are failing. i will ask WHY
> you are forking out for stuff perl does easily?
> 
> 
>   RA> my $url = $ARGV[0];
>   RA> my $now = `date +%s`;
> 
> POSIX::strftime does all that date does
> 
>   RA> my $differential='360';
>   RA> my $transitfile = "wdtimekeeper";
> 
>   RA> my $cleanup = system("unlink $transitfile");
> 
> perl has unlink builtin
> 
>   RA> if (! $cleanup) {
>   RA>         print $!;
>   RA> }
> 
>   RA> my $wget=system("wget $url$transitfile");
> 
> wget is done in perl with LWP.
> 
>   RA> print "$wget\n";
>   RA> if (! $wget)    {
>   RA>         print $!;
>   RA> }
> 
>   RA> my $laststamp = `cat $transitfile`;
> 
> useless use of cat in perl! several very easy and fast ways to read in a
> file. my File::Slurp::read_file is easy, fast and very popular.
> 
>   RA> open FH1,"+>","$transitfile" || print "cant\n";
>   RA> print FH1 $now;
>   RA> close FH1;
> 
> the same module has write_file. why do you open with +> when you are
> just writing a fresh timestamp?
> 
>   RA> my $curl = system("curl -k -T $transitfile $url");
> 
> from what i know about curl, LWP can do that.
> 
> so if you stick with perl your code would be clearer, shorter, faster
> and have fewer issues with system and backticks (in fact no issues).
> 
> uri

This is the real reason I choose perl over php when I want to code 
something on a Unix system. Plus there are MacOS extensions.  It's all 
part of the program, built-in.

-- 
DeeDee, don't press that button!  DeeDee!  NO!  Dee...
[I filter all Goggle Groups posts, so any reply may be automatically ignored]




------------------------------

Date: Thu, 21 Feb 2013 09:29:58 -0500
From: "R. Allen" <rocallen@cisco.com>
Subject: Re: system commands exit 1 [corrected]
Message-Id: <51262F66.2010100@cisco.com>

Thank you GURUS for the advice.  I will rewrite my commands in perl 
where possible.  Thanks again!

On 2/21/2013 3:38 AM, Michael Vilain wrote:
> In article <87ppzuhziq.fsf@stemsystems.com>,
>   Uri Guttman <uri@stemsystems.com> wrote:
>
>>>>>>> "RA" == R Allen <rocallen@cisco.com> writes:
>>
>>
>> i won't address how or why your system calls are failing. i will ask WHY
>> you are forking out for stuff perl does easily?
>>
>>
>>    RA> my $url = $ARGV[0];
>>    RA> my $now = `date +%s`;
>>
>> POSIX::strftime does all that date does
>>
>>    RA> my $differential='360';
>>    RA> my $transitfile = "wdtimekeeper";
>>
>>    RA> my $cleanup = system("unlink $transitfile");
>>
>> perl has unlink builtin
>>
>>    RA> if (! $cleanup) {
>>    RA>         print $!;
>>    RA> }
>>
>>    RA> my $wget=system("wget $url$transitfile");
>>
>> wget is done in perl with LWP.
>>
>>    RA> print "$wget\n";
>>    RA> if (! $wget)    {
>>    RA>         print $!;
>>    RA> }
>>
>>    RA> my $laststamp = `cat $transitfile`;
>>
>> useless use of cat in perl! several very easy and fast ways to read in a
>> file. my File::Slurp::read_file is easy, fast and very popular.
>>
>>    RA> open FH1,"+>","$transitfile" || print "cant\n";
>>    RA> print FH1 $now;
>>    RA> close FH1;
>>
>> the same module has write_file. why do you open with +> when you are
>> just writing a fresh timestamp?
>>
>>    RA> my $curl = system("curl -k -T $transitfile $url");
>>
>> from what i know about curl, LWP can do that.
>>
>> so if you stick with perl your code would be clearer, shorter, faster
>> and have fewer issues with system and backticks (in fact no issues).
>>
>> uri
>
> This is the real reason I choose perl over php when I want to code
> something on a Unix system. Plus there are MacOS extensions.  It's all
> part of the program, built-in.
>



------------------------------

Date: Wed, 20 Feb 2013 13:28:10 -0500
From: "R. Allen" <rocallen@cisco.com>
Subject: system commands exit 1
Message-Id: <1361384890.555824@rcdn-nntpcache-3>

Hello list,

I cannot seem to figure out why theses commands are returning 1;

wget returns 1 with "bad file descriptor"
curl returns 1 with " ENOTTY (Inappropriate ioctl for device)"

Any assistance would be appreciated.

#!/usr/bin/perl

use strict;

my $url = $ARGV[0];
my $now = `date +%s`;
my $differential='360';
my $transitfile = "wdtimekeeper";

my $cleanup = system("unlink $transitfile");
if (! $cleanup) {
         print "no file\n";
}

my $wget=system("wget $url$transitfile");
print "$wget\n";
if (! $wget)    {
         exit 1;
}

my $laststamp = `cat $transitfile`;

open FH1,"+>","$transitfile" || print "cant\n";
print FH1 $now;
close FH1;

my $curl = system("curl -k -T $transitfile $url");
#system("curl -d -k -T $transitfile $url");
if (! $curl)    {
         print "1\n";
}
my $a = $now - $differential;

if ($a > $laststamp)    {
         exit 1;
}


------------------------------

Date: Wed, 20 Feb 2013 18:51:49 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: system commands exit 1
Message-Id: <5jifv9-hv.ln1@anubis.morrow.me.uk>


Quoth "R. Allen" <rocallen@cisco.com>:
> Hello list,
> 
> I cannot seem to figure out why theses commands are returning 1;
> 
> wget returns 1 with "bad file descriptor"
> curl returns 1 with " ENOTTY (Inappropriate ioctl for device)"
> 
> Any assistance would be appreciated.
> 
> #!/usr/bin/perl
> 
> use strict;
> 
> my $url = $ARGV[0];
> my $now = `date +%s`;
> my $differential='360';
> my $transitfile = "wdtimekeeper";
> 
> my $cleanup = system("unlink $transitfile");

Perl has unlink built in.

> if (! $cleanup) {
>          print "no file\n";
> }
> 
> my $wget=system("wget $url$transitfile");
> print "$wget\n";
> if (! $wget)    {

system returns 0 on success (but be careful, because some failure modes
return undef).

Ben



------------------------------

Date: Wed, 20 Feb 2013 14:19:20 -0500
From: "R. Allen" <rocallen@cisco.com>
Subject: Re: system commands exit 1
Message-Id: <512521B8.40301@cisco.com>

On 2/20/2013 1:51 PM, Ben Morrow wrote:
>
> Quoth "R. Allen" <rocallen@cisco.com>:
>> Hello list,
>>
>> I cannot seem to figure out why theses commands are returning 1;
>>
>> wget returns 1 with "bad file descriptor"
>> curl returns 1 with " ENOTTY (Inappropriate ioctl for device)"
>>
>> Any assistance would be appreciated.
>>
>> #!/usr/bin/perl
>>
>> use strict;
>>
>> my $url = $ARGV[0];
>> my $now = `date +%s`;
>> my $differential='360';
>> my $transitfile = "wdtimekeeper";
>>
>> my $cleanup = system("unlink $transitfile");
>
> Perl has unlink built in.
>
>> if (! $cleanup) {
>>           print "no file\n";
>> }
>>
>> my $wget=system("wget $url$transitfile");
>> print "$wget\n";
>> if (! $wget)    {
>
> system returns 0 on success (but be careful, because some failure modes
> return undef).
>
> Ben
>

Unlink corrected.  Thanks Ben.  These commands seem to be returning 
errors from the OS.  I have noticed that my file perms on this host are 
strange.  For instance, I can open, write, and save the file, but I 
cannot redirect into it (echo "hello perl" > file fails).


------------------------------

Date: Wed, 20 Feb 2013 16:33:23 -0500
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: system commands exit 1
Message-Id: <87liaiu0v0.fsf@new.chromatico.net>

>>>>> "RA" == R Allen <rocallen@cisco.com> writes:

    RA> I have noticed that my file perms on this host are strange.  For
    RA> instance, I can open, write, and save the file, but I cannot
    RA> redirect into it (echo "hello perl" > file fails).

Two points -- 

1. the ability to create or delete a file in a directory is a permission
of the directory, not of the file.  See perlfaq5, "Why does Perl let me
delete read-only files?" 

2. many shells have a setting that prevents you from accidentally
overwriting a file.  In C shell, it's called noclobber. If foo exists,
and this setting is on, echo "text" > foo will fail.  This is not a
function of file permissions, but of the shell settings.

Charlton


-- 
Charlton Wilbur
cwilbur@chromatico.net


------------------------------

Date: Thu, 21 Feb 2013 01:09:03 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: system commands exit 1
Message-Id: <fm8gv9-r45.ln1@anubis.morrow.me.uk>


Quoth Charlton Wilbur <cwilbur@chromatico.net>:
> >>>>> "RA" == R Allen <rocallen@cisco.com> writes:
> 
>     RA> I have noticed that my file perms on this host are strange.  For
>     RA> instance, I can open, write, and save the file, but I cannot
>     RA> redirect into it (echo "hello perl" > file fails).
> 
> Two points -- 
> 
> 1. the ability to create or delete a file in a directory is a permission
> of the directory, not of the file.  See perlfaq5, "Why does Perl let me
> delete read-only files?" 

A third point:

1a. Many editors write a file by writing a new file and then renaming it
over the old. This does not actually require write permission on the
file, though at least some editors check the permissions and warn you if
you are trying to overwrite a readonly file like this.

Ben



------------------------------

Date: Thu, 21 Feb 2013 20:18:15 +0100
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: system commands exit 1
Message-Id: <512672f7$0$6985$e4fe514c@news2.news.xs4all.nl>

On 2013-02-20 19:28, R. Allen wrote:

> open FH1,"+>","$transitfile" || print "cant\n";

That line has many issues.

- global file handle
- quoted variable (or overloaded object?)
- wrong 'or' precedence

-- 
Ruud



------------------------------

Date: Thu, 21 Feb 2013 13:48:08 -0500
From: Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid>
Subject: Re: system commands exit 1
Message-Id: <51266be8$4$fuzhry+tra$mr2ice@news.patriot.net>

In <87liaiu0v0.fsf@new.chromatico.net>, on 02/20/2013
   at 04:33 PM, Charlton Wilbur <cwilbur@chromatico.net> said:

>1. the ability to create or delete a file in a directory is a
>permission of the directory, not of the file.

That is true for *ix; it is not true in general.

OTOH, the most notable exception is MVS, and Perl has been frozen
there at 5.8.7 due to EBCDIC-Unicode issues.

-- 
Shmuel (Seymour J.) Metz, SysProg and JOAT  <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to spamtrap@library.lspace.org



------------------------------

Date: Thu, 21 Feb 2013 22:58:45 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: system commands exit 1
Message-Id: <5eliv9-vlj1.ln1@anubis.morrow.me.uk>


Quoth Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid>:
> In <87liaiu0v0.fsf@new.chromatico.net>, on 02/20/2013
>    at 04:33 PM, Charlton Wilbur <cwilbur@chromatico.net> said:
> 
> >1. the ability to create or delete a file in a directory is a
> >permission of the directory, not of the file.
> 
> That is true for *ix; it is not true in general.

That's a good point.

> OTOH, the most notable exception is MVS, 

Win32 (and therefore NFSv4 and ZFS) have separate 'delete' and 'delete
child' permissions. Either is sufficient to delete a file (and neither
permits writing, which is what the OP was trying to do).

> and Perl has been frozen
> there at 5.8.7 due to EBCDIC-Unicode issues.

Due to IBM not giving a damn.

Ben



------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 3884
***************************************


home help back first fref pref prev next nref lref last post