Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
|
 |
10-20-2005, 08:48 AM
|
#1
|
Member
Registered: Sep 2004
Distribution: Knoppix 4.0.2
Posts: 54
Rep:
|
How do I script these commands?
Hi All,
I'd like to be able to script these commands but don't know how to write shell scripts, can anyone offer a simple example?
Cheers
J
su root
parted -s /dev/hda mkpartfs primary fat32 1 8000
cat /proc/partitions
cd /UNIONFS/mnt
mkdir fat32
chown knoppix fat32
chmod 755 fat32
mount -0 rw,umask=0, /dev/hda1 /UNIONFS/mnt/FAT32
ifconfig eth0 add 130.209.13.209 netmask 255.255.255.0
|
|
|
10-20-2005, 09:05 AM
|
#2
|
Senior Member
Registered: Oct 2005
Location: Horgau, Germany
Distribution: Manjaro KDE, Win 10
Posts: 2,199
Rep: 
|
Hello!
---------------------------script beginning
#!/bin/bash
parted -s /dev/hda mkpartfs primary fat32 1 8000
cat /proc/partitions
cd /UNIONFS/mnt
mkdir fat32
chown knoppix fat32
chmod 755 fat32
mount -0 rw,umask=0, /dev/hda1 /UNIONFS/mnt/FAT32
ifconfig eth0 add 130.209.13.209 netmask 255.255.255.0
|
|
|
10-20-2005, 09:12 AM
|
#3
|
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
|
At its simplest scripting can just be putting everything you do into a file and making it an executable by using the chmod command to add the execute bit.
Therefore you could just add everything you typed below into a single file and try it but HOLD ON. It won't work but ONLY because you're doing the "su" first. When you do "su" you're actually starting a new shell so none of the commands following would be exeucted until AFTER you'd exited the "su".
Due to above you just need to modify it slightly. Make 2 scripts.
The first one would include everything below your "su root".
The second one would be a one liner that does:
su root -c <firstscript> (or su root --command=<firstscript>) where <firstscript> is the actual name of the first script you'd created.
The "-c" says to execute the command that follows which in this case would be the name of the first script you'd created.
You SHOULD but don't have to include the shell directive at the beginning of the script. This is only so the script always uses the shell you expect regardless of the shell the invoking user is running. The shell directive for bash would be:
#!/bin/bash
Note that the "#" is required - this is a special non-comment usage. Also note that this MUST be the first line of the script.
Finally I note that you wrote "su root". If you do that it does not get root's environment - it inherits the invoking user's environment. You should probably do "su - root" instead to be sure it always has root's environment.
|
|
|
10-21-2005, 08:34 AM
|
#4
|
Member
Registered: Sep 2004
Distribution: Knoppix 4.0.2
Posts: 54
Original Poster
Rep:
|
Hi Guys,
Thanks for this.
jlightner thanks for such a comprehensive answer!! I often find it difficult to understand WHY certain things have to be done in a certain way and being a relative n00b to Linux it's all still very confusing....but fun :-)
Many Thanks
Johnnybhoy
|
|
|
10-21-2005, 09:20 AM
|
#5
|
Member
Registered: Sep 2004
Distribution: Knoppix 4.0.2
Posts: 54
Original Poster
Rep:
|
Hi jlightner,
I've done as you suggest but I get the error " : bad interpreter: No such file or directory"
I suppose this would be a good time to mention that this is a knoppix live CD but that shouldn't make a difference I don't think as /bin/bash exists.
Any ideas?
Cheers
J
|
|
|
10-21-2005, 09:42 AM
|
#6
|
LQ Guru
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
|
From your error it appears its finding a space or a null.
Make sure the directive line is the TOP LINE in the file and that there are no spaces in it:
#!/bin/bash
As noted previously the # (number/pound sign) is required as is the ! (exclamation point).
Type "ps" and see what shell you are using. If you're already using bash you can leave out the directive from your script. By the way you don't need it it the script that is doing the su as it is invoking a new shell based on user setup. ("grep root /etc/passwd" to see which shell root has - it's at the end of the line).
Try typing "/bin/bash" at the command line and see if it gives you a new shell. If so then just type exit to go back to your original one. This will at least confirm it is finding /bin/bash and executing it.
I'm not familiar with the knoppix live CD - I guess its possible its not allowing for this but I wouldn't think so since it is fairly basic operation of shell scripting.
|
|
|
10-21-2005, 09:53 AM
|
#7
|
Member
Registered: Sep 2004
Distribution: Knoppix 4.0.2
Posts: 54
Original Poster
Rep:
|
ok getting a bit further now.....
Removed the #!/bin/bash from teh top line and I now get prompted for the root password. But I don't want to be prompted for the password, is there any way around this??
Cheers
John
|
|
|
All times are GMT -5. The time now is 04:15 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|