Jshee
Jshee

Reputation: 2686

python script run commands as needed

I need to run these commands as needed. Preferably I'd like to double click the file, and have the commands run, then the file closes.

However, when I run the command via open terminal on ubuntu and type ./start_wifi.py it fails with:

$ ./start_wifi.py 
^C./start_wifi.py: line 6: syntax error near unexpected token `"rfkill unblock all"'
./start_wifi.py: line 6: `os.system("rfkill unblock all")'

here is my script:

#!/bin/bash

import os
import time

os.system("rfkill unblock all")
print("\nunblocked wlp5s0\n")
os.system("sudo iwlist wlp5s0 scan")
print("\nscanned for wireless networks\n")
os.system("sudo ip link set wlp5s0 up")
print("\nbrought up wlp5s0...\ngive it 5 seconds...\nsleeping now\n")
time.sleep(5)
exit()

What can I do to achieve this?

Upvotes: 1

Views: 63

Answers (1)

janos
janos

Reputation: 124824

The code is in Python but the shebang #!/bin/bash is Bash. Change the first line to this:

#!/usr/bin/env python

Upvotes: 1

Related Questions