in reply to system() call mis-directs?
Check the values of $sensor for which the error occurs. Do they contain other bits of shell syntax such as ampersands, semicolons, or a trailing backslash? Any of those could cause the shell to misparse the remainder of the command.
Try instead: (obviously untested)
my $result = system(q[./upgrade.pl "].quotemeta($sensor).q[" >>worklo +g 2>&1]);
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: system() call mis-directs?
by haukex (Archbishop) on Mar 03, 2020 at 07:43 UTC | |
quotemeta($sensor) Sorry, but quotemeta is not an appropriate shell quoting function - it may work in some cases, but will fail in others. I would strongly recommend e.g. ShellQuote::Any instead, or of course to avoid the shell in the first place. | [reply] [d/l] |
by afoken (Chancellor) on Mar 03, 2020 at 21:35 UTC | |
ShellQuote::Any The code currently looks like this:
Just from looking at the names of the functions, it has only two modes of operation: Either Windows, or Bourne Shell. No code for handling cygwin, OS/2 or DOS, so those three will be treated as Bourne Shell, which is plain wrong. On Windows, you simply can not win the quoting game. Any code pretending to be able to do so is broken. Assuming that all other systems use a bourne-compatible shell as default shell is at least optimistic. Severals systems have a korn shell as default, others even use a csh. See Various system shells. Looking at the documentation of String::ShellQuote, handling the non-Windows part, the problem is obvious without even reading the source:
It seems nobody cared during the last 10 years, and the author either had no time to RTFM, or had no idea where to search for shell man pages. So, with ShellQuote::Any, you are essentially lost if the current default shell is no bourne shell. I did not bother to read the quoting code in String::ShellQuote. As is, it is broken anyway, and with it ShellQuote::Any. Yes, it may work on many systems in their default configuration, but it won't do its job on all systems. It does not even prevent stupid things from happening on unknown systems. Alexander
-- Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-) | [reply] [d/l] |
by jcb (Parson) on Mar 04, 2020 at 00:55 UTC | |
I currently believe that quotemeta will work within the context of a double-quoted argument with the Bourne shell. I was concerned mostly with ensuring that any quotes embedded in $sensor would not terminate the quoted argument early (I suspect that some of the $sensor values contain characters that separate commands) and quotemeta seems to be a tool usable for this special case. If I am wrong, please provide a counter-example where quotemeta fails to cause a string to be passed exactly as written as an argument. That code was written off the top of my head and not tested so I could be very wrong here... In this case, it is wrong anyway because $sensor consists of multiple arguments that the shell is expected to split, and I did immediately suggest finding a solution that does not involve using the shell after an example input was provided. | [reply] [d/l] [select] |
Re^2: system() call mis-directs?
by Clarkman (Novice) on Mar 03, 2020 at 01:05 UTC | |
@sundialsvc4, thank you but logs have been checked and re-checked. @jcb, you may have nailed it. $sensors looks like this: ABC-00-DEF-1234 --sitename=Charon .The double hyphen is suspicious as is the '=' Will test out tomorrow and post results. Thank you ! | [reply] |
by jcb (Parson) on Mar 03, 2020 at 02:42 UTC | |
Your sample does not contain any troublesome characters, but the shell splits on unquoted whitespace, which my earlier suggestion would prevent by wrapping $sensor in shell quotes before passing it to the shell. My immediate suspicion is that you may have some "odd" site names. In particular, an ampersand is both reasonable in human-readable names and special to the shell. The best way to fix this would be to get the shell out of the picture and use the list form of system. You will also need to use open or sysopen to rearrange your filehandles so that the second child will inherit STDOUT and STDERR opened for append on the worklog file, while the first child keeps its original STDOUT somewhere to report the result from the second child. | [reply] [d/l] [select] |
| |
Re^2: system() call mis-directs?
by Clarkman (Novice) on Mar 05, 2020 at 00:11 UTC | |
Every time the daemon while(1) looped forever, it stopped over at waitpid: The meaning of the intermediate process was not clear. Upon completion of the system() call, it prints and exits. Its sole purpose seems to allow catching the $result into the daemon's log, but we don't care. So we switched over to exec(): Now the process tree looks like this: Much simpler. From running the daemon on the command line, we now saw that the output of the fork/exec'd upgrade-sensor.pl process was writing into the daemon's log. More specifically, the daemon's log created thus, when the daemon was launched: (Still need to write an init.d/ controller). What we did to make it work (we think) was to kill off dup handles, and re-open. We added the two close commands at the head of the upgrade-sensor.pl script, and now logs are properly separated. Love inheriting code! What we don't know is whether this is correct, or not. It works on two hosts the same way:
so that's good. But these messages are not coming from our code, rather the first issues upon calling fork. The second issues from waitpid.
Yes, it is ->Unknow<-. Thanks again - Clarkman | [reply] [d/l] [select] |
by Clarkman (Novice) on Mar 05, 2020 at 02:33 UTC | |
| [reply] |
by jcb (Parson) on Mar 06, 2020 at 00:04 UTC | |
You are running some tee processes that you should not need with that. Try something more like: (untested)
| [reply] [d/l] |