|Just another Perl shrine|
Automating execution of shell scriptsby wisely (Initiate)
|on Aug 30, 2021 at 11:22 UTC||Need Help??|
wisely has asked for the wisdom of the Perl Monks concerning the following question:
Hi all, This is my first post here and my question is not so much about the exact code implementation at this stage but rather what is the best way to achieve this and is it possible.
So I have these two shell scripts that I need to run to create environments for my work and I can't make any changes to the shell scripts themselves.
So the first shell script takes in files as well as a few arguments and created a directory based on them and it also prints in the terminal the path to the created dir.
So for example my first script will look like this: ~/shell_1.csh file1 arg1 arg2
And the output from it will be a directory like this (number after the underscore is the date):
I created a perl script to automate the execution of the above shell script I just give it all the files I need and it extracts the needed argument and runs the shell script for each one.
The second shell script I need to execute in each of the created directories.
So for the above example I would change my dir to /project/file1/file1_270821 and then execute shell_2.csh in it.
This is tedious if I have just created 5 such directories for example, so I want to automate this.
What i was thinking is to have it check the directories for all files I have passed to it and run the second shell script in the one with the latest date.
So for example if I have passed file1, my perl script to go into the /project/file1 dir, find the file1_* with the latest date and then run the shell_2.csh in that dir.
Is it possible for this to be achieved with perl? If yes is the way with checking dates the most efficient way?