0

I am using python and trying to execute a system command as below

code.py

import commands
import os

os.system('updatedb')

result:

sh-4.2$ python code.py
updatedb: can not open a temporary file for `/var/lib/mlocate/mlocate.db'

So how to execute all the system commands like above from a python module ?

4
  • The error indicates that you do not have permissions to run the updatedb command. Commented Feb 27, 2013 at 7:00
  • 1
    This has nothing to do with the fact that it was called from Python. Have you tried running updatedb in the command line? You'll almost certainly get the same error. Commented Feb 27, 2013 at 7:00
  • Are you sure this isn't just a permissions problem? Commented Feb 27, 2013 at 7:00
  • yes actually when i tried it in terminal without entering in to root... its displaying the same error, but when i tried from root executed successfully.... so finally there is no way to get the rsult from python by getting in to root or making this executable ? Commented Feb 27, 2013 at 7:04

1 Answer 1

3

This is almost certainly simply a permissions problem. If you can trust your script to run as root:

$ sudo python code.py
Sign up to request clarification or add additional context in comments.

2 Comments

Just because i usually run it in linux server to update db and perform some additional operations with help of cron jobs. so in server that too with cron jobs it is not possible to provide a password to run the script
@Fedrik: In that case, it sounds like the issue is getting that cron job to run as root.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.