ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
Hi All
I have made sample test driver for linux. Now I want to do insmod & mknod using shell script.In my shell script I am able to insert the module (i.e. insmod), but not able to do mknod because I am not able to get major number value. I print the variable major but it is blank .
By doing cat /proc/devices major number exist. But in awk command I am doing something wrong which I am unable to find out. Down is the source for script .
Code:
#!/bin/sh
module="char-dev-reg"
device="char-dev-reg"
mode="664"
/sbin/insmod ./$module.ko $* || exit 1 //insmod happing
# remove stale nodes
rm -f /dev/${device}[0-3]
major=$(awk "\$2==\"$module\" {print \$1}" /proc/devices)
echo "major='$major'" //HERE MAJOR VALUE IS BLANK
echo "module='$module'"
mknod /dev/${device} c ${major} 0
Not an awk expert, or even competant at it, however I know of no device named "char-dev-reg". Like for me the type of devices I make nodes for would be ttyUSB and in my /proc/devices file I have a line saying:
Code:
188 ttyUSB
so I would be searching for that exact string.
When your module is inserted, what line does show up in your /proc/devices file? Show that line and even given my lack of awk experience, someone else who does have good awk experience can probably help you with your setting of the major mode.
// cannot be used as comment sign in shells, you should use # instead
I think that's just a comment within their code block and not really in their shell. Instead just the point they're identifying where they've detected the variable is not the expected value.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.