Jump to content

two shell script examples needed...


ktambascio
 Share

Recommended Posts

Hi,

 

I want to write two shell scripts for my linux system, to make it more friendly. The first one, I know how to write it, but I'm not sure where to put it to allow it to run. The first one, is a script that would only run once, when I add a user. For every user, I want to set up a bunch of symbolic links, and set certain environment variables. Well, I guess the symbolic links would only have to be created once, but setting env variables could run everytime.

 

The second script, would be the commands to get more than one X session going. I have used the commands (can't remember them now though) that would put a new X session onto the CTRL-ALT-F8 screen, and would have a new KDM, so that I could log into KDE on that second session, or someone else could log in without me having to log out of the F7 session. I know you can manually do that, but I wanted to have a script somewhere that would set it up automatically, so that when I boot up, I could immediatly hit CTRL-ALT-F8 and log into the second session without running any scripts on my own. I just don't know where/how to put a script so that it runs in that fashion.

 

Thanks,

Kevin

Link to comment
Share on other sites

Script 2: it is not a script, actually. You only have to add a line to the /etc/inittab file. Can you tell me what does your file look like (it depends on the version you use; I use Mdk8.1)?

On the other hand, if you replace KDM with GDM as the login chooser (no risk, and no need to switch to Gnome if you don't want to), then there's an option in Mandrake's main menu to open a new login screen on AltF8 with a single click, and you can add more: AltF9, AltF10... That's what I do at home.

 

Script 1: Do you want to run this script manually (but only once) when you create a new user, or do you want this script to be run automatically by (or after) whichever tool (which one?) you use to create users?

Please answer, but whatever the answer, the solution looks like a script, that contain first a bunch of commands to run on the new home-directory to add links and things like that. Then (in the same script), a command like this one:

cat >>~newuser/.bashrc <<-THEEND

...put your environment variables here...

THEEND

 

'later.

 

Yves.

Link to comment
Share on other sites

cannonfodder:

 

I did not know what the profile.d files were, I'll take a look at them, I think that can work fine.

 

Yves:

 

I am using Mandrake 9. I'll post my inittab file at the bottom. I use KDE and KDM. Can you tell me what lines to add so that I can get KDM's on F8, F9, and F10? that would be really helpful.

 

[kevin@localhost etc]$ cat inittab

#

# inittab This file describes how the INIT process should set up

# the system in a certain run-level.

#

# Author: Miquel van Smoorenburg, <miquels@drinkel.nl.mugnet.org>

# Modified for RHS Linux by Marc Ewing and Donnie Barnes

#

 

# Default runlevel. The runlevels used by Mandrake Linux are:

# 0 - halt (Do NOT set initdefault to this)

# 1 - Single user mode

# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)

# 3 - Full multiuser mode

# 4 - unused

# 5 - X11

# 6 - reboot (Do NOT set initdefault to this)

#

id:5:initdefault:

 

# System initialization.

si::sysinit:/etc/rc.d/rc.sysinit

 

l0:0:wait:/etc/rc.d/rc 0

l1:1:wait:/etc/rc.d/rc 1

l2:2:wait:/etc/rc.d/rc 2

l3:3:wait:/etc/rc.d/rc 3

l4:4:wait:/etc/rc.d/rc 4

l5:5:wait:/etc/rc.d/rc 5

l6:6:wait:/etc/rc.d/rc 6

 

# Things to run in every runlevel.

ud::once:/sbin/update

 

# Trap CTRL-ALT-DELETE

ca::ctrlaltdel:/sbin/shutdown -t3 -r now

 

# When our UPS tells us power has failed, assume we have a few minutes

# of power left. Schedule a shutdown for 2 minutes from now.

# This does, of course, assume you have powerd installed and your

# UPS connected and working correctly.

pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"

 

# If power was restored before the shutdown kicked in, cancel it.

pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"

 

 

# Run gettys in standard runlevels

1:2345:respawn:/sbin/mingetty tty1

2:2345:respawn:/sbin/mingetty tty2

3:2345:respawn:/sbin/mingetty tty3

4:2345:respawn:/sbin/mingetty tty4

5:2345:respawn:/sbin/mingetty tty5

6:2345:respawn:/sbin/mingetty tty6

Link to comment
Share on other sites

[kevin@localhost etc]$ cat inittab

id:5:initdefault:

 

si::sysinit:/etc/rc.d/rc.sysinit

 

l0:0:wait:/etc/rc.d/rc 0

l1:1:wait:/etc/rc.d/rc 1

l2:2:wait:/etc/rc.d/rc 2

l3:3:wait:/etc/rc.d/rc 3

l4:4:wait:/etc/rc.d/rc 4

l5:5:wait:/etc/rc.d/rc 5

l6:6:wait:/etc/rc.d/rc 6

 

ud::once:/sbin/update

ca::ctrlaltdel:/sbin/shutdown -t3 -r now

pf::powerfail:/sbin/shutdown -f -h +2 "Power Failure; System Shutting Down"

pr:12345:powerokwait:/sbin/shutdown -c "Power Restored; Shutdown Cancelled"

 

1:2345:respawn:/sbin/mingetty tty1

2:2345:respawn:/sbin/mingetty tty2

3:2345:respawn:/sbin/mingetty tty3

4:2345:respawn:/sbin/mingetty tty4

5:2345:respawn:/sbin/mingetty tty5

6:2345:respawn:/sbin/mingetty tty6

The lines l0 to l6 run in runlevel 0 to 6 (see between the : ). Lines 1 to 6 all run in runlevers 2, 3, 4, and 5 (0 -halt- and 6 -reboot- are special: in those modes, no login screen is opened, obviously).

On my PC, there's an additionnal line that looks like:

x:5:respawn:/usr/X11R6/bin/prefdm

or something like that. As you don't have this line, I conclude that your display manager is run from this line:

l5:5:wait:/etc/rc.d/rc 5

which means that /etc/rc.d/rc is run with parametter 5. In short, this should mean that rc will run every script in /etc/rc.d/rc5.d, the name of which begins with the letter S. One of those should somehow run your prefered display manager (this preference can be changed in /etc/sysinit/desktop on the DISPLAYMANAGER= line).

 

I don't have the details of your runlevel5 scripts, so I'll propose an alternative to using them. See the above code? it says ":wait:", which means that the following of the file won't be read until this script has finished running. So after this line, we're sure (for runlevel 5) that your display manager has started on CtrlAltF7. I propose to add this at the end of /etc/inittab:

x8:5:wait:/usr/X11R6/bin/X -query 127.0.0.1 :1

x9:5:wait:/usr/X11R6/bin/X -query 127.0.0.1 :2

xA:5:wait:/usr/X11R6/bin/X -query 127.0.0.1 :3

This should work, but you may have to first configure KDM to allow XDMCP connexions.

 

Yves.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...