Python Forum

Full Version: help with a simple script
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi

im really new to python so i wrote this script:

#!/usr/local/bin/python

service postgresql start
service postgresql restart
msfdb reinit


i gave it the right permissions:

oot@kali:~# chmod u+x start_msf.py

the problem is that when i try to execute it i get an error which i dont unserstad:

oot@kali:~# python start_msf.py
File "start_msf.py", line 3
service postgresql start


thanks a lot to all !
someone? please?
Sorry, but that not even looks like python... if I have to bet it looks like a bash script to launch services (like systemctl or the good old rc)

If you want to access to an existing SQL db, you can do it with the DB-API (see Python Wiki to choose a module to install) but I think you first need a few hours with the python tutorial or everything is going to sound really strange... or maybe you are following a tutorial and mixed the commands to start the DB service from the command line with the real python script.

To explain a little bit the error, it is saying that the line service postgresql start is not a valid python expression.
thnks a lot !!
killerrex is right, what you are trying to do is bash-scripting. and are trying to stop and start the database server running on you system.
If you want to access a database work with a python database package. There are different packages working best with different kinds of databases, take a look here:
https://www.fullstackpython.com/databases.html
Psycopg should do the trick for you