473,320 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Python & Linux, some questions

Hello,
i need some answers...

1) I need to run some linux commands (from inside my app) that require
superuser privileges (mkfs, losetup, etc), how do i do that? (I do not
want to run my app with root privileges, but it will just ask the user
for the root password before proceeding)
2) When i execute the command i need to read its output (especially the
error messages) to know if everything went fine but i do not know how :(
3) How can i know if the user that is running my app is root or normal user?

Thank you,
Luca
Jul 18 '05 #1
7 1591
Luca T. wrote:
1) I need to run some linux commands (from inside my app) that
require superuser privileges (mkfs, losetup, etc), how do i do
that? (I do not want to run my app with root privileges, but it
will just ask the user for the root password before proceeding)
man sudo(1), su(1) or setuid-bit (chmod(1))
2) When i execute the command i need to read its output (especially
the error messages) to know if everything went fine but i do not
know how :
see the popen family of functions in the Python library.
( 3) How can i know if the user that is running my app is
root or normal user?


os.getuid()

Mathias
Jul 18 '05 #2
Mathias Waack wrote:
Luca T. wrote:
1) I need to run some linux commands (from inside my app) that
require superuser privileges (mkfs, losetup, etc), how do i do
that? (I do not want to run my app with root privileges, but it
will just ask the user for the root password before proceeding)

man sudo(1), su(1) or setuid-bit (chmod(1))


Hmmmm,
ok... "sudo" requires me to modify the user's system (or in other words
write in /etc/sudoers), a thing that i don't want to do. My app has not
to change the configuration of the machine.
Same thing for setuid-bit/chmod.

This leaves me with "su"... but there is a problem... "su" doesn't
execute any command, it just gives you a "prompt" as root (or another
user)... how can use this?

Thank you,
Luca
Jul 18 '05 #3
Luca T. wrote:
This leaves me with "su"... but there is a problem... "su" doesn't
execute any command, it just gives you a "prompt" as root (or
another user)... how can use this?


Please read su(1) until you find the answer. Or use the right group;)

Mathias
Jul 18 '05 #4
Mathias Waack wrote:
Please read su(1) until you find the answer. Or use the right group;)


Damn, you are right, thanx... now i wonder why sudo exists though... oh
well.

Bye,
Luca
Jul 18 '05 #5
a magic combination of both would be the command:

sudo su -

:)

make a shell "script" out of it:

#!/bin/bash
sudo su -

call it "root", make it executable to everyone, put it in /usr/local/bin or
any other path in $PATH, add all users on your system to /etc/sudoers...

and just run your new "root" command and enjoy.. ok, of course you should
not do so!
by using "root" you can now have a root shell withouth having to type a
password every time :/

Luca T. wrote:
Mathias Waack wrote:
Please read su(1) until you find the answer. Or use the right group;)


Damn, you are right, thanx... now i wonder why sudo exists though... oh
well.

Bye,
Luca


Jul 18 '05 #6
I use pexpect to telnet and ssh...

"Luca T." <lu***@despammed.com> wrote in message
news:c3*************@ID-99001.news.uni-berlin.de...
Hello,
i need some answers...

1) I need to run some linux commands (from inside my app) that require
superuser privileges (mkfs, losetup, etc), how do i do that? (I do not
want to run my app with root privileges, but it will just ask the user
for the root password before proceeding)
2) When i execute the command i need to read its output (especially the
error messages) to know if everything went fine but i do not know how :(
3) How can i know if the user that is running my app is root or normal user?
Thank you,
Luca

Jul 18 '05 #7
On Sun, 14 Mar 2004 23:09:51 +0100, "Luca T." <lu***@despammed.com>
declaimed the following in comp.lang.python:
Damn, you are right, thanx... now i wonder why sudo exists though... oh
well.
sudo doesn't require the root password, only the authorized
user's password. It can also be configured to only allow access to
certain commands, not everything.

-- ================================================== ============ <
wl*****@ix.netcom.com | Wulfraed Dennis Lee Bieber KD6MOG <
wu******@dm.net | Bestiaria Support Staff <
================================================== ============ <
Home Page: <http://www.dm.net/~wulfraed/> <
Overflow Page: <http://wlfraed.home.netcom.com/> <

Jul 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
3
by: james blair | last post by:
Hi I have a search page & the reults for the search are fetched from the database. I want that on the results page only first 25 results are shown & a link "next 25 results" be shown.Same for the...
114
by: Maurice LING | last post by:
This may be a dumb thing to ask, but besides the penalty for dynamic typing, is there any other real reasons that Python is slower than Java? maurice
3
by: Ron Guerin | last post by:
The New York Linux User's Group invites you to a special presentation by Alex Martelli of Google, on the Python Object Model. This presentation will be held at P.J. Clarke's Sidecar, rather than...
0
by: Ron Guerin | last post by:
(date and time inadvertently omitted last time. sorry!) The New York Linux User's Group invites you to a special presentation by Alex Martelli of Google, on the Python Object Model. This...
1
by: Sandeep | last post by:
Hi, I want to read & print a UTF-8 encoded characters stored in a file. I want to write a C program on Linux platform to achieve this. I am new to UTF-8. I will appreciate any sample...
9
by: James Stroud | last post by:
Hello All, I have been trying to make an https client with python, but it seems that, to do this, one needs to have the socket module compiled with ssl. This is not the default. So I have a...
34
by: Anthony Irwin | last post by:
Hi All, I am currently trying to decide between using python or java and have a few quick questions about python that you may be able to help with. #1 Does python have something like javas...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.