Execute permission denied for perl script - perl

I call a perl script from shell script.Since both unix shell script and perl script are created by me, i was able to execute it successfully.But when i deploy the code using anthillpro, permission of the files changed to 644. Hence when others execute this shell script, they are able to run unix script but following error is received while calling perl script.
0403-006 Execute permission denied.
Following code is used to invoke my perl script from unix shell script:
/usr/bin/perl /home/script/conversion.pl $layout_file $format_file $conv_file $base_filenm $COREPATH
First line of my perl script has following line:
#!/usr/bin/perl
Can anyone provide a solution for this issue ?

Related

Run perl script from tcl

I have a perl script that I manually run it from shell:
myScript.pl -from_session=Session1234 -to_session=Session6789 -port=104:3445
I try to run it from tcl, in this way, but it doesn't work....
set script_path "myScript.pl";
set sessionA "Session1234";
set sessionB "Session6789";
set p "104:3445";
exec perl $script_path -from_session=$sessionA -to_session=$sessionB -port=$p
Update:
I found that the perl script is done, but the tcl script is not continue after the execution of the perl script.
TCL doesn't need semicolon at the end. Once removed, I tried to execute exec command on one of my PERL script in tclsh and it works fine.
Therefore my suggestion is to try executing the program in tclsh to see weather some error is returned and most importantly to give the full absolute path to the script. All in all, try
set script_path "/absolute/path/to/myScript.pl"
set sessionA "Session1234"
set sessionB "Session6789"
set p "104:3445"
exec perl $script_path -from_session=$sessionA -to_session=$sessionB -port=$p

Unable to execute Perl script unless Perl is inserted before script name

Running Lubuntu -
Beginner Perl programmer
Script is XXX.pl located at ~/projects/XXX/XXX.pl
First line is the shebang
#!/usr/bin/perl
Permission to run is set to Anyone.
In directory ~/projects/XXX, the command
~/projects/XXX$ perl XXX.pl
works as desired, but the command
~/projects/XXX$ XXX.pl
Fails with XXX.pl: command not found
What am I missing ?
The two usual options to execute your Perl script are:
perl XXX.pl
or
./XXX.pl
Both ways assume that your current working directory contains the script XXX.pl, otherwise it won't work.
As already pointed out by jm666 in the comments, you can usually not execute a program or script from your current working directory without prepending ./, primarily because of security reasons. Now, you may wonder why it's necessary.
Explanation:
Your shell uses the contents of an environment variable called $PATH to find out about where external commands (non-builtin programs) are located in your filesystem. If you want to see what's in $PATH, just type the following in your shell:
echo $PATH
Now you can see that the $PATH variable does NOT contain your current working directory. The consequence is that your shell is not able to find the program XXX.pl. By prepending ./ you instruct the shell to execute the program which comes after.
But there are two requirements if you want to execute your Perl script with ./script.pl:
The script has to be executable (check with ls -l)
The first line (shebang line) has to be #!/path/to/your/perl because your shell needs that information to find the perl interpreter in order to run your script
However, #1 and #2 are NOT required when you execute your script with
perl XXX.pl
because it invokes the perl interpreter directly with your script.
See how to make Perl scripts executable on Linux and make the script itself directly executable with chmod for some more details.
Can the script be found?
Is . in your path? If it's not, add it to your path, or use ./XXX.pl instead of XXX.pl.
Can the script be executed?
Do you have execute permission to the file? Fix using chmod u+x XXX.pl.
Is the interpreter correct?
which perl will tell you which interpreter is used when you use perl XXX.pl. That's the path that should be on your shebang (#!) line.

Run Perl script directly from GitHub

I am trying to run a Perl script directly from GitHub. This thread seems to address my issue (indeed, it helped me run dofiles in Stata directly from GitHub). However, when I type the following in a command prompt:
"perl https://rawgit.com/EconJoe/medline2014-xmlparsers/master/desc2014_meshtreenumbers.pl"
I get The following error message:
"Can't open perl script "https://rawgit.com/EconJoe/medline2014-xmlparsers/master/desc2014_meshtreenumbers.pl": Invalid argument"
Thanks for any help.
perl can't fetch a script from a URL. You have to do that separately.
curl -L https://rawgit.com/EconJoe/medline2014-xmlparsers/master/desc2014_meshtreenumbers.pl | perl

Trouble Running Perl Script from within Shell Script

I am trying to run a perl script from within a *.csh script, but I get the following error:
Can't open perl script "checkLength.perl": No such file or directory
I think it has something to do with the path of the perl script. I can run a perl script fine when it's not being called within the shell script, but a perl script won't run when I have it being called in the cshell script.
The shebang I use for the perl script is : #!/usr/bin/perl. I checked, and perl is located there (not in /usr/bin/env perl). I made sure it's executable.
Do I need to edit the $PATH to get this to work? I'm confused because if I run a perl script without calling it within another csh script, it runs just fine.
Of course one obvious solution to your problem would be to simply use the full path to the script. But this is often not preferable, as the script would brake on installations that do not mirror exactly the original structure.
So there are two possibilities:
Either you put your perl script into a well defined location that is contained in your PATH variable so any program that runs under the respective users environment finds it.
Or you have some well defined location relative to the location of your calling script. Say your bash script is located in somedir and you perl script is in somedir/subdir, then your call would be subdir/perlscript.pl. Then, to become independent of possible changes in the working directory of the caller, you could determine the current full path of the perl script to be called on start of the bash script.
A template for this would be:
#!/bin/bash
FULLPATH=$(pwd)/subdir/somescript.pl
# do something else, cd ...
$FULLPATH
I am assuming your Perl script is kept in a fixed path relative to your bash script. Assuming your directory structure to be like so:
(BASEDIR)/bin/example.sh
(BASEDIR)/perl/example.pl
To allow you to run your bash script from anywhere in your system you must specify the relative path to your Perl script by getting the BASEDIR.
#!/bin/bash
BASEDIR=$(dirname $0)
perl $BASEDIR/../perl/example.pl
What we are doing above is finding the location of your bash script(BASEDIR/bin) that you call and then finding the relative location of the Perl script using the location of the bash script as reference. Now you will be able to call the bash script from anywhere and run your Perl script normally.

not able to invoke a perl script from a c shell script

i am a writing csh script that invokes a perl script. The perl script loads some .pm files but one of the .pm file is giving errors, i do not know perl scripting, please help.
Can't exec "uname": No such file or directory at /grid/cic/common/bin/../modules/plat.pm line 67.
uname is not in the executing user's path. You'll have to change the user's permissions or do a setuid.