LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-31-2006, 07:39 PM   #1
jazman
LQ Newbie
 
Registered: May 2006
Posts: 13

Rep: Reputation: 0
perl pl and sh files


I need to execute a script on a linux machine via a cron scheduler.

I currently have a .pl script file which I can run on my Win xp box with a perl interpreter.

This linux setup has specified it can only run .sh script files.

Can I just rename the script file to .sh, or is there considerable difference between these 2 file types?
 
Old 05-31-2006, 07:49 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Hi, and welcome to LQ!

sh is a shell-script, pl is a perl script. If the
linux machine doesn't support perl there's nothing
you can do to make the perl-script run. You can try
to re-write it in bash.


Cheers,
Tink
 
Old 05-31-2006, 08:20 PM   #3
jazman
LQ Newbie
 
Registered: May 2006
Posts: 13

Original Poster
Rep: Reputation: 0
Pl files

Hi there

The linuz box has a perl interpreter on it.. however it says it will only run .sh files....

does this makes sense
 
Old 05-31-2006, 08:21 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Not reallly ... who owns the box?
 
Old 05-31-2006, 08:55 PM   #5
peter72
Member
 
Registered: Oct 2002
Location: Charlottesville, VA
Distribution: Ubuntu (home), SLES (work)
Posts: 196
Blog Entries: 1

Rep: Reputation: 30
Write a quick bourne shell script to call the perl script.

Code:
#!/bin/sh
/usr/bin/perl /home/peter/bin/myspecialscript.pl
exit 0
 
Old 05-31-2006, 08:58 PM   #6
jazman
LQ Newbie
 
Registered: May 2006
Posts: 13

Original Poster
Rep: Reputation: 0
Commview

Hi there,

Its a commview box..linux firewall sort of thing

The manual has a bunch of examples of scripts that can be run.

all start with #!/usr/bin/perl

but the file name for the script is file.sh



any thoughts
 
Old 05-31-2006, 09:06 PM   #7
jazman
LQ Newbie
 
Registered: May 2006
Posts: 13

Original Poster
Rep: Reputation: 0
Will do

Thanks Peter and tinkster for the prompt replies. will try this one out.

Cheers
ill keep you posted
 
Old 05-31-2006, 10:32 PM   #8
dinojerm
Member
 
Registered: Apr 2004
Location: NJ,US
Distribution: Debian Sid
Posts: 33

Rep: Reputation: 15
Quote:
Originally Posted by jazman
all start with #!/usr/bin/perl
If the scripts contain that as the first line, they will be interpreted by perl when executed; they are probably actually perl scripts. While the .sh extension usually signifies sh shell scripts, if a perl script is named that way, the perl script will be executed.
Although it seems strange for the system to require .sh extensions,
you should be able to run your perl script as long as its first line is #!/usr/bin/perl
 
Old 06-01-2006, 02:27 AM   #9
timmeke
Senior Member
 
Registered: Nov 2005
Location: Belgium
Distribution: Red Hat, Fedora
Posts: 1,515

Rep: Reputation: 61
Indeed, the restriction on .sh extensions for executable programs is ridiculous.
Linux doesn't really care about file extensions (unlike Windows).
The fact that the system can run Perl scripts (since it has the necessary interpreter) under a "fake" file extension, proves that the restriction isn't effective.
 
Old 06-04-2006, 07:13 AM   #10
dannybpng
Member
 
Registered: Sep 2003
Location: USA
Distribution: Fedora 35
Posts: 79

Rep: Reputation: 22
To run the file from a cron job just add the command like what peter72 suggested into the cron file and the perl interpreter will run the script.

/usr/bin/perl /home/peter/bin/myspecialscript.pl

FYI
The #!/usr/bin/perl as the first line of a file is interpreted by the shell script interpreter (sh,bash,... that is prompting for a command) when the command is typed at the prompt. The file is then passed to the specified program (/usr/bin/perl in this case) to execute. You can use whatever command interpreter you need. This gives you the ability to mark a file as executable (chmod u+x ...) put it in the PATH and when you type that command at the prompt it will run.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
perl files download instead of parsed on apache2 mod-perl2 not parsing perl files zeigerpuppy Debian 1 02-16-2006 05:31 AM
PERL Upload Files dsheller Programming 11 12-22-2005 11:29 PM
mv files with perl provkitir Programming 6 03-04-2005 01:02 AM
perl files andox Programming 4 09-28-2004 06:04 PM
Converting perl files to executable mac files mrozkan Programming 0 04-16-2002 09:56 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration