Python and PuTTY

Posted on 2006-04-03
Last Modified: 2007-02-13
before i start - im total new to LINUX OK!

the other day i changed from using a Microslops Windoses Server to a LINUX Server.

PHP, Perl & CGI, C++ and Python are all enabled on the LINUX server.  I have never used a python script and wanted to know how to run one.

I then contacted my host to find out how to run pythons scripts on there server and basically was told to use PuTTY adn was giving my username and password to connect to SSH something or other.

I downloaded PuTTYa nd installed it on my laptop and conected to the LINUX server, but after that - forget it - total lost.

I have no knowledge of using LINUX or its commands ut im willing to learn.

hoping somebody can provide me with some help to how to run a python script and give it permissions to run i think -im not too sure what the technical support guys are meaning about permissions...

anyways hope to hear from somebody soon...
Question by:ellandrd
    LVL 3

    Accepted Solution

    It sounds like the python isn't the problem or at least not yet.  First you need to learn a bit about Linux and it's shell.  The shell is the command line interface between you and the operating system much like windows "command prompt".  So now to give you a few pointers.  When you log in you will be in your "home directory" you can see where you are by typing in "pwd" (without "") which means present working directory (directory = folder).  To see what's in the directory type "ls" (lowercase LS) is like "dir" on windows.To move around you us "cd" just like in windows, cd .. to go up one directory, cd somedir to go into the somedir sub-directory, or cd /home/myuser/somedir to go directly to where ever you need to go.

    So now you can move around the filesystems (some what similar to drives in Windows like c: or d: there are no drives like this in Linux, filesystems attach to the / filesystem by mounting (windows mapping) to a directory) .  the top of the filesystem is called root and is shown just by a "/".  So to get to the root of the computer just type "cd /".  To see what filesystems are on your system type in "df -h"  this will list all local and network mounted filesystems.  

    Now you'll need to find you python scripts which probably under /usr somewhere.  If your lucky findutils will be installed and you can type in "locate pythonscriptname" and it will tell you where it is.

    Once you find it you can run it by cd'ing to the directory it's in and running ./pythonscript   or from anywhere on the system by giving the full path name of the script /usr/local/python/pythonscript.

    Also sometime you should go pick up a book of which there are thousands for Learning linux because while it's really pretty easy there is a lot of content.  Also use the man pages which will give you all the details of most any command by typing in man <command> for instance "man ls"
    LVL 16

    Author Comment

    ok thank you for these commands - they will be very helpful!

    >>Once you find it you can run it by cd'ing to the directory it's in and running ./pythonscript   or from anywhere on the system by giving the full path name of the script /usr/local/python/pythonscript.

    ok my full path looks like this:


    my python script is called so how do i call it?

    like this:



    LVL 16

    Author Comment

    Mmm cant get the python script to run...

    here: i copied and pasted from the PuTTY...

    Using username "domain1019017".'s password:
    Last login: Mon Apr  3 20:07:11 2006 from
    [domain1019017@ssh5 ~]$ pwd
    [domain1019017@ssh5 ~]$ ls
    htdocs  logfiles  private
    [domain1019017@ssh5 ~]$ cd htdocs
    [domain1019017@ssh5 htdocs]$ pwd
    [domain1019017@ssh5 htdocs]$ ls
    cgi-bin  entrance_logo.png  ERT  index.php  jws  mysql  php  python  robots.txt
    [domain1019017@ssh5 htdocs]$ cd python
    [domain1019017@ssh5 python]$ ls
    [domain1019017@ssh5 python]$ index
    -bash: index: command not found
    [domain1019017@ssh5 python]$ locate
    [domain1019017@ssh5 python]$
    -bash: exec: not found

    hope this makes sence to you
    LVL 3

    Expert Comment

    The last attempt there should work if you call it like "./"

    Linux has a PATH variable just like windows but most times your current directory is not in the path so ./ tells the shell where the file is in relation to the current directory (which is . )  Also you could run it right from your home directory with  "./htdocs/python/ "  depending on the script however it might assume you are running it from the current directory.  

    "locate" did find another but there are bound to be many, also it looks like the index file that locate uses hasn't been updated so run "updatedb".  This takes a few minutes.  You may need to be root to run that if so type in "su -" and then the root password then run "updatedb" .  To get back to your own shell enter <ctrl>D  

    Hope that helps

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Join & Write a Comment

    In my business, I use the LTS (Long Term Support) versions of Linux. My workstations do real work, and so I rarely have the patience to deal with silly problems caused by an upgraded kernel that had experimental software on it to begin with from a r…
    The purpose of this article is to demonstrate how we can use conditional statements using Python.
    Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
    Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now