Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Automating execution of shell scripts

by roboticus (Chancellor)
on Aug 30, 2021 at 13:42 UTC ( [id://11136208]=note: print w/replies, xml ) Need Help??


in reply to Automating execution of shell scripts

wisely:

From your description, it sounds like you have all the information you need in the first script to run the second script, so I'd suggest either wrapping things up into a single script *or* letting your first script write your second script.

For the first option, one common way to do it is to use perldoc -f fork to split your process so you can have your original process do the work you're currently doing in your first script, and then have the copied process do the work you'd do in the second script. There are also some packages on CPAN that help you manage multiple jobs that you may want to investigate.

I generally use the second option, though, which is to write your second script from your first. Since you already have a script that does the second task, all you really need to do is create a shell script to run the second task with the parameters you've created in the first task. Then once your first script runs, you can execute the new script that it creates, or even add some code to the end of your script to execute the script automatically.

#!env perl use strict; use warnings; open my $FH, '>', 'task_part_two.sh' or die "Can't create script 'task_part_two.sh': $!\n"; while (my $arg = shift) { print "Setting things up for task $arg\n"; # . . . do the work for the first script . . . # Create a new directory name my $the_dir = "dir_" . int(1000*rand); # build the directory and put the required file in it # Now that it's set up, write the command to run the # second script print $FH "/the/script/path.sh '$the_dir' '$arg'\n"; }

...roboticus

When your only tool is a hammer, all problems look like your thumb.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11136208]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-04-19 03:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found