I am currently running ubuntu 16.04. I have a python script that is supposed to create a symlink from the current linux header directory to /usr/src/linux:
The script was given as text for me to copy. I have saved the the code into a file which I named script.py. Now when I tried to run the script.py with a sudo ./script.py command it did not work. I have also tried calling the file script (no .py extension) and running sudo ./script but that doesn't work either.
I have also tried just running the script with python interpreter like: python script.py (py3 interpreter) and I think it ran but I am not sure. My question is:
Is there something I have to do to the script in order to get it to run with a ./ command on linux? I have ran scripts before with ./ command why won't this one run that way?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#!/usr/bin/env python import os import sys import subprocess def _runningKernel(): result = subprocess.check_output([ 'uname' , '-r' ]).strip() return result def _kernelHeaderPath(kernelName): return os.path.join( '/' , 'usr' , 'src' , 'linux-headers-%s' % kernelName) _linkName = os.path.join( '/' , 'usr' , 'src' , 'linux' ) _headersPath = _kernelHeaderPath(_runningKernel()) if not os.path.isdir(os.path.join(_headersPath, '.' )): sys.stderr( "Error: Did not the header files directory at %s\n" % _headersPath) sys.exit( 1 ) if ( not os.path.islink(_linkName)) and os.path.exists(_linkName): sys.stderr( "Error: %s is not a symlink. (Cowardly refusing to overwrite it.)\n" % _headersPath) sys.exit( 1 ) if os.path.islink(_linkName): os.remove(_linkName); os.symlink(_headersPath, _linkName) |
I have also tried just running the script with python interpreter like: python script.py (py3 interpreter) and I think it ran but I am not sure. My question is:
Is there something I have to do to the script in order to get it to run with a ./ command on linux? I have ran scripts before with ./ command why won't this one run that way?