For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > January 2006 > Quoting question









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Quoting question
Michael Weber

2006-01-25, 6:57 pm

Greetings!

I am not completely understanding how perl parses quotes.

Here is the line I want to execute:

exec "$command $cmd_msg";

The variable $command is an executable shell script "test.sh"

The problem comes in the $cmd_msg variable.

This contains a line from my log file:

Nov 13 11:54:31 fw-3 sshd(pam_unix)[19906]: authentication failure; =
logname=3D uid=3D0 euid=3D0 tty=3Dssh ruser=3D rhost=3D82-148-208-172.fiber=
..unet.nl

The shell script blow up on the parenthesis:

sh: -c: line 0: syntax error near unexpected token `('

How can I quote the exec line above so what gets passed to /bin/sh is the =
log file line contained in double quotes?

Thanx!




E-MAIL CONFIDENTIALITY NOTICE: This communication and any associated
file(s) may contain privileged, confidential or proprietary
information or be protected from disclosure under law ("Confidential
Information"). Any use or disclosure of this Confidential Information,
or taking any action in reliance thereon, by any individual/entity
other than the intended recipient(s) is strictly prohibited. This
Confidential Information is intended solely for the use of the
individual(s) addressed. If you are not an intended recipient, you
have received this Confidential Information in error and have an
obligation to promptly inform the sender and permanently destroy,
in its entirety, this Confidential Information (and all copies
thereof). E-mail is handled in the strictest of confidence by
Allied National, however, unless sent encrypted, it is not a secure
communication method and may have been intercepted, edited or
altered during transmission and therefore is not guaranteed.


Chas Owens

2006-01-25, 6:57 pm

snip
> How can I quote the exec line above so what gets passed to /bin/sh is the=

log file line
> contained in double quotes?

snip

Use a different quoting mechanism:

exec qq($command "$cmd_msg");

or use a the multiple argument version of exec():

exec $command, $cmd_msg;

You may also want to use system instead of exec(). exec() replaces
the current process with the one specified. system() issues a fork()
followed by an exec().
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com