Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

perl and linux

by Anonymous Monk
on Oct 26, 2003 at 16:25 UTC ( [id://302213]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I have 2 questions that I need help with please. I will admit that I am relatively new to perl.

I am using perl on a linux red-hat machine, I am renting space on the webserver so I only have telnet access to the machine.

1) how do I install perl modules on this machine (I can install them on my pc, but I only have telnet and ftp to the webserver, and not root privelege)?

2) when I try to execute perl scripts without using the format 'perl $0' I get I get a 'command not found' message. I know that I need to set an environment variable in my .bashrc file so that it knows what to do with .pl files, but I don't know the command/format. Please help.

thanx!
-Kevin

Replies are listed 'Best First'.
Re: perl and linux
by kutsu (Priest) on Oct 26, 2003 at 16:36 UTC

    To execute a perl script without using perl blah.pl: first make sure the file has execute permissions (chmod 0700), then maker sure your PATH includes ./ (if it don't: add it to your /home/username/.bash_profile, PATH=./:/usr/bin:...). To install a module look at this guide written by tachyon in the Tutorials Section.

    "Pain is weakness leaving the body, I find myself in pain everyday" -me

      Or if a user other than your good self needs to execute the program, chmod 0755

      -- vek --

        Like the web server for instance...... :-)

        cheers

        tachyon

        s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      Typically ./ is excluded from the path for security reasons. Probably not a big deal in this case (there are more single user, a.k.a. desktop, machines running linux these days than multi-user servers per se). But say on a multi-user machine, some mischevious user creates a bash script called "ls" and puts it in some group writable directory that you do much work in. According to your PATH that ls would be called before the real ls and it would do whatever that mischevious person created it to do. For example, mail your ssl private key to themselves, or /etc/shadow if you foolishly have ./ in your path as root. Of course, their script would then call the real ls then delete itself and you would be none the wiser.

      Anyway, I'm not picking on your advice, I would just like people to be aware that ./ is excluded from the path for a very good reason. If you just get used to typing ./program.pl now, you might save yourself problems in the future.

        Okay all you people are right, I forgot he said it was networked. Okay forgot isn't the right word, I have been setting up Linux machines for the past few weeks, all single user or small group of user machines, so I just put the steps I used to make my scripts work.

        Don't use ./ in the path and use 0755 so others can use your scripts, if you want them to (but remember root can see all ;)

        "Pain is weakness leaving the body, I find myself in pain everyday" -me

      thanx
Re: perl and linux
by mandog (Curate) on Oct 26, 2003 at 19:47 UTC

    A couple other things you might consider:

    • You also need a shbang line
    • You might not want to change your path to include the '.'

    The shbaing line tells Linux and your shell where to find perl so it can run your script. Somethingn like this:

    '#!/usr/bin/perl -w '

    ...as the very first line of your script. Don't include the quotes, but do include the space after the -w

    The -w and the space are not strictly necessary but they are useful.

    The -w will give you helpful extra error messages. For more details see: perldoc perlrun

    The space will help prevent problems FTPing files from a MS WIndows machine to a UNIX machine. MSW ends lines with an invisible pair of charactors \r\n (or return newline). Unix doesn't see a \r as very special. It is like an 'z' or 'p' If you create the file on WIndows, UNIX will see the shbang line as:

    #!/usr/bin/perl -w\r

    give you an error message and refuse to run. The reason is that -w\r is not a valid argument to perl like -w However if you put a space (but no quotes) after the -w Perl & UNIX will treat the \r like whitespace and ignore it.

    You might not want to put the '.' into your path to avoid other peoples evil programs. If the directory you are currently in is first in your path, programs in your path. Suppose you do this:

    cd ~buddy ls

    suppose your friend has a script like this:

    #!/bin/sh rm ~/* -rf echo ha ha ha

    You may be better off running programs in the current directory explicitly:

     ./myscript.pl
      Thanx for everyone's suggestions. I did have one more question along the same lines. Following the tutorial as recommended in the beginning, I should have put "LIB=~/lib" in as an modifier for the makefile.pl instruction the first time I ran MCPAN and it asked me for all of the system values etc. I did not, how do I get it to reask me all those questions?

      -Kevin

        How do I get CPAN to ask me the configuration questions

        locate CPAN/Config.pm $EDITOR /path/to/CPAN/Config.pm

        if updatedb hasb't run, you'll have to use find

Re: perl and linux
by etcshadow (Priest) on Oct 26, 2003 at 19:45 UTC
    Oh, and as far as how to install new modules without root access: make a perllib directory under your home directory. Add this directory to your PERL5LIB environment variable (in your shell's rc-file). When you install the new module, there should be a parameter to the "configure" shell script for something along the lines of --basedir or something like that (look at the README and/or INSTALL files that come with the module). You can specify that so that when you run "make install" it installs the code into your personal perl-library directory instead of the root ones.

    There's a similar parameter for use with CPAN.pm, but you can look at the docs for it. I don't know off the top of my head, and you're just as capable of reading "man CPAN" as I am. :-D

    Also, you could just send an email to your system's administrator asking him/her to install these modules for you... they just might do it, if you

    • ask them politely
    • explain what it is, what it is for (and maybe why other users of the system might want it)
    • give them the command to install it (like, "cd /home/me/some_module/; make install" or "perl -MCPAN -e 'install some_module'")
    Sysadmins aren't (generally) evil monsters. You needn't fear them (unless, for example, the MotD on your system is "Fear the wrath of root!" or some such :-D).

    ------------
    :Wq
    Not an editor command: Wq

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2024-03-29 02:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found