[Tutor] Python for linux

Alan Gauld alan.gauld at btinternet.com
Tue Jan 27 19:18:46 CET 2015


On 27/01/15 16:50, Reuben wrote:

> I wish to know which python module works well with Linux commands

Most Python modules work on Linux if you are running your Python program 
on a Linux machine.

> e.g. Searching a string in file, number of occurrences of a string in a
> file,

Thee isn't a specific module for that but you can write a Pyhon function 
to do that quite easily. Or you can call the OS tools
(such as grep)

 > what is the permission of a file.

The OS module does include functions for that kind of work though.

> To test this operation I need my python script to login into the Linux
> machine and then perform the above mentioned operations

So what kind of machine is your program running on? If it is a Windows 
box then that's a very different thing to running commands on a local 
Linux PC. Normally your put the Python script on the target Linux 
machine if possible then remotely login and run that script.
You appear to want to run the script locally and run commands remotely 
on a Linux box. very different. For that you probably want to run OS 
commands using the ssh (or telnet? or pyexpect?) modules.

But that brings another bunch of issues.

But if you are just reading files can you mount those files on the 
network so that your local script can see the drive/folder? Then
you can do it all from python.

> Any specific pointers to help me with this task?

We need a clearer explanation of what you are tying to do.
ie the actual problem you are trying to solve rather than the
coding approach you are trying to use.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list