I'm trying to write a script to setup environment variables depending on which environment the user wants to be in. However, it dies at the final line of code with this:
Can't exec ". /opt/lnpsite/nm02/scripts/setup_env": No such file or di
+rectory at ./opSet.pl line 27, <STDIN> line 1.
Cannot execute . /opt/lnpsite/nm02/scripts/setup_env: No such file or
+directory
I'm not entirely sure why the code is dropping out there because I was able to copy and paste the "non-existant" directory and run it from the command line.
Anyway, here is the code. I cannot seem to figure out why it is not running.
#!/opt/perl5/bin/perl -w
use strict;
my @instances; my $i = 1;
my $selection = 0;
opendir OPHOME, "/opt/lnpsite" or die "Can't open /opt/lnpsite: $!\n";
my @files = sort(readdir(OPHOME));
foreach(@files){
if (m/(op|nm)\d{2}$/) {
push(@instances, $_);
}
}
print "\nAvailable Instances";
print "\n===================\n";
foreach(@instances) {
print " $i. ",$_,"\n"; $i++;
}
print "\nSelect an instance and press enter: ";
$selection = <STDIN>; chomp($selection);
$selection = $selection - 1;
my $conn = ". /opt/lnpsite/" . $instances[$selection] . "/scripts/setu
+p_env";
print "$conn\n";
exec $conn $instances[$selection] or die "Cannot execute $conn: $!\n";
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.