A quick google brings up this, is this the "sbatch" / SLURM you're talking about? https://computing.llnl.gov/linux/slurm/sbatch.html

If that's the case, and if my understanding from a quick skim is correct, then this isn't a plain bash script! There seems to be some preprocessing being done that reads the #SBATCH lines - as has already been noted, lines beginning with # are just comments to bash.

You'll either need to find a monk who's worked with this system before, or give everyone else a quick overview of how this system works.

I will still venture two guesses as to how this might still work with Perl. First, perhaps the system understands more than bash scripts. # lines are just comments to Perl too, so maybe this could work?

#!/usr/bin/perl #SBATCH -A 1234 #SBATCH -t 2-00:00 #SBATCH -n 24 use warnings; use strict; system("module add gromacs")==0 or warn "Warning: module add failed, code $?"; system("srun resp.com")==0 or warn "Warning: srun failed, code $?";

(This requires "module" and "srun" to be actual commands in your PATH, and not some directives that only sbatch understands.)

Or, even though this isn't exactly a "conversion to Perl", it still gives some control to Perl - this uses IPC::Run3 to feed the "script" to sbatch via STDIN.

#!/usr/bin/perl use warnings; use strict; use IPC::Run3 'run3'; my $script = <<'END_SCRIPT'; #!/bin/bash #SBATCH -A 1234 #SBATCH -t 2-00:00 #SBATCH -n 24 module add gromacs srun resp.com END_SCRIPT run3 ["sbatch"], \$script;

Even though that's really just a simple wrapper, it still gives you some of the power of Perl, such as being able to generate the script dynamically or do advanced things with STDOUT and STDERR.

I want to convert it to Perl it because I will add on it the other parts after it works.

Sorry, I don't understand, could you explain a bit more?


In reply to Re: How can I convert my script for submitting SLURM jobs from Bash to Perl? by Anonymous Monk
in thread How can I convert my script for submitting SLURM jobs from Bash to Perl? by erhan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.