[Linux-disciples] Opening the wrong file
Adam Kessel
linux-disciples@bostoncoop.net
Sat, 22 Nov 2003 11:23:04 -0800
--Q68bSM7Ycu6FN28Q
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
On Thu, Nov 13, 2003 at 10:56:39AM -0500, Stephen R Laniel wrote:
> Is this easy to do?
No. I don't think there's any easy way to detect where the input is
coming from. After all, a pipe redirects standard input from a file.
The better way to do what you want would be:
zcat /var/log/apache/access.log.10.gz |~/log -
I believe that will accomplish your goal without having to change your
perl code.
=2E..
> I just noticed a bug in a little Apache-log post-processing script that I
> wrote. If the user specifies an input file on the command line
> ('log [filename]'), the script opens that input file; otherwise the
> script defaults to opening /var/log/apache/access.log. The relevant chunk
> of code is
>=20
> my $logfile =3D (@ARGV ? $ARGV[0] : '/var/log/apache/access.log');
> #[...]
> open( STDIN, "<$logfile" )
> or die "Could not open $logfile.\n";
>=20
> The trouble I just noticed is that if I try to use syntax like
>=20
> zcat /var/log/apache/access.log.10.gz |~/log
>=20
> it doesn't work: the script doesn't recognize that a file has been piped
> in, so it uses /var/log/apache/access.log.
>=20
> Is there a way to fix this? The logic I want is
>=20
> * if a file's been piped in, use that.
> * if a file's been specified on the command line, use that.
> * if both a pipe and a file have been specified ... figure out this
> case at some other time
> * if neither a pipe nor a file have been specified, use
> /var/log/apache/access.log.
>=20
--=20
Adam Kessel
http://bostoncoop.net/adam
--Q68bSM7Ycu6FN28Q
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
iD8DBQE/v7eYdTf3ZklQ6qYRAsa+AJ9pSpu+HF3fP10pPQGAbVB8nEzzMgCdEu3P
IS+86ef2j9T3aDipu7nIN8E=
=q11S
-----END PGP SIGNATURE-----
--Q68bSM7Ycu6FN28Q--