On Thu, Sep 24, 2009 at 4:02 PM, Jeff Squyres
<jsquyres@cisco.com> wrote:
The DoCommand.pm sub added ":\n" to the beginning to force the Bourne shell interpreter. This is necessary for some cases where an interpreter is not otherwise specified.
Im not familiar with :\n semantics, how does it force Bourne shell and what it actually does :)? (seems like leftovers from 1960....)
I think when interpreter is not explicitly specified - the default user`s shell is used.
see in the DoCommand::Cmd() ..... it check the buffer`s first line for #!/... semantic and if found - saves buffer to file, adds +x perm, and just executes it as a regular script.
When I passed a buffer with shell commands but 1st line was not #!/bin/sh - it failed with syntax errors.
I see why you did it -- you want the ability to add your own interpreter in &shell_script(). Why not either make a parameter to add the ":\n" or not, or better yet, have DoCommand.pm analyze the beginning of the string and if it contains "^:\n" or "^#!", then don't add anything. But if it doesn't contain either of those, then prefix it with ":\n".
How does that sound?
sounds good!
Also, is "&shell_script()" a good name? If you can specify your own interpreter, it might not be a shell script. How about &executable()?
ok - &executable() it will be!
regards
Mike
On Sep 24, 2009, at 8:06 AM,
miked@osl.iu.edu wrote:
Author: miked
Date: 2009-09-24 08:06:04 EDT (Thu, 24 Sep 2009)
New Revision: 1319
URL: https://svn.open-mpi.org/trac/mtt/changeset/1319
Log:
bug fix: CmdScript() - no need to add extra chars "\n:" to the start of shell script file
new funclet: shell_script(section,param)
Text files modified:
trunk/lib/MTT/DoCommand.pm | 2 +-
trunk/lib/MTT/Values/Functions.pm | 19 +++++++++++++++++++
2 files changed, 20 insertions(+), 1 deletions(-)
Modified: trunk/lib/MTT/DoCommand.pm
==============================================================================
--- trunk/lib/MTT/DoCommand.pm (original)
+++ trunk/lib/MTT/DoCommand.pm 2009-09-24 08:06:04 EDT (Thu, 24 Sep 2009)
@@ -797,7 +797,7 @@
$cmds =~ s/\"$//
if ($cmds =~ s/^\"//);
- print $fh ":\n$cmds\n";
+ print $fh "$cmds\n";
close($fh);
chmod(0700, $filename);
Modified: trunk/lib/MTT/Values/Functions.pm
==============================================================================
--- trunk/lib/MTT/Values/Functions.pm (original)
+++ trunk/lib/MTT/Values/Functions.pm 2009-09-24 08:06:04 EDT (Thu, 24 Sep 2009)
@@ -3026,4 +3026,23 @@
return md5_hex($str);
}
+# Run shell commands as a script, i.e
+#
+# [mtt]
+# myscript=<<EOT
+# #!/bin/sh
+# pwd
+# ls
+# EOT
+# on_stop=&shell_script("mtt",myscript)
+#
+#
+
+sub shell_script {
+ my ($cmd_section, $cmd_param) = @_;
+ my $cmd = &get_ini_val($cmd_section, $cmd_param);
+ my $x = MTT::DoCommand::CmdScript(1, $cmd);
+ return $x->{result_stdout};
+}
+
1;
_______________________________________________
mtt-svn mailing list
mtt-svn@open-mpi.org
http://www.open-mpi.org/mailman/listinfo.cgi/mtt-svn
--
Jeff Squyres
jsquyres@cisco.com
_______________________________________________
mtt-devel mailing list
mtt-devel@open-mpi.org
http://www.open-mpi.org/mailman/listinfo.cgi/mtt-devel