[SOLVED] Method to check if symlink from the current linux header directory to /usr/src/linux exists?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Method to check if symlink from the current linux header directory to /usr/src/linux exists?
So I was given a script as text. Apparently the script will generate a symlink from the current linux header directory to /usr/src/linux. I took the text and created a file copied it into the file and saved it as script.py. I then tried running the script with a sudo ./script command but that doesn't work. So I tried saving the file as script without the .py extension and tried running ./script but that did not work either.
I am not sure why those attempts did not work but I tried just running it with an interpreter via a sudo python script and it might have worked? I have no way of knowing because I don't even know what a symlink is.
Number one is that you should consider learning what symbolic links are.
Freely available on the web and my personal explanation is that they are just a pointer to a file that is somewhere else in your system. Therefore you see the file in whichever directory you are visiting, and can view it, run it, etc, just the physical file is somewhere else.
You should post this script and place it within [code] tags to retain the formatting of it and then people can help you better. I'm not sure if the whole purpose of that script is just to create a symbolic link, it might be. Meanwhile there is a command line command which makes symbolic links in a single call, ln(1)
Finally. Since you were given this script. Ask the person who gave it to you, and make sure you trust the origin of anything before you try to run it.
#!/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)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.