LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to run script (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-run-script-665398/)

unikgila 08-25-2008 10:16 PM

how to run script
 
Hi,

I found one script on the linux device driver book
Code:

#!/bin/sh
module="scull"
device="scull"
mode="664"
# invoke insmod with all arguments we got
# and use a pathname, as newer modutils don't look in . by default
/sbin/insmod ./$module.ko $* || exit 1
# remove stale nodes
rm -f /dev/${device}[0-3]
major=$(awk "\\$2=  =\"$module\" {print \\$1}" /proc/devices)
mknod /dev/${device}0 c $major 0
mknod /dev/${device}1 c $major 1
mknod /dev/${device}2 c $major 2
mknod /dev/${device}3 c $major 3
# give appropriate group/permissions, and change the group.
# Not all distributions have staff, some have "wheel" instead.
group="staff"
grep -q '^staff:' /etc/group || group="wheel"
chgrp $group /dev/${device}[0-3]
chmod $mode  /dev/${device}[0-3]

I still confuse how to save this script (what name and where should i save it) and how to run this script.

I usually didn't use script instead of just running one by one command to load my module by using (insmod, mknod, chmod)

MS3FGX 08-25-2008 10:18 PM

Save it as whatever you like, though it is usually a good idea to give it the extension ".sh". Then you make the file executable by running the command "chmod +x filename"; after that you can run the script from the terminal or from within your GUI file manager.

klearview 08-25-2008 10:23 PM

file name doesn't matter (you can call it <file>.sh but it's really not important). Create empty file:

touch <file>

Open it with editor:

vim <file>

Press 'i' on your keyboard to enter 'insert' mode.

Copy/paste the text of your script.

Press 'Esc'
Type ':wq' to save it.

Make the file executable:

chmod +x <file>

Run it (make sure you are in the same directory as file):

./<file>

unikgila 08-25-2008 11:18 PM

klearview and MS3FGX,

Thank you for quick response, improve my knowledge and now i happy to use script


All times are GMT -5. The time now is 07:51 AM.