LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   Run a Script at the boot up before login (https://www.linuxquestions.org/questions/linux-kernel-70/run-a-script-at-the-boot-up-before-login-4175529527/)

mgayandk 12-30-2014 12:24 AM

Run a Script at the boot up before login
 
hi,
i need to write a script to boot up process before login the user.and by using that script select the run level.

what i need is when linux os boot ,it should wait until user give the user name and password. according to the username and password given by user the script will be select the run level.

note: user name and password should be in separate text file.and the script should run at the booting time.

users credentials should be stored in script


please help :)

astrogeek 12-30-2014 12:34 AM

It doesn't work that way.

What are you actually trying to accomplish?

mgayandk 12-30-2014 12:52 AM

Quote:

Originally Posted by astrogeek (Post 5292376)
It doesn't work that way.

What are you actually trying to accomplish?

i need to run a script at the boot up and wait for user input, i have write a script to init file and rc.local. scrypt run without waiting user input. what i need is, need a script which should wait until user input

astrogeek 12-30-2014 01:21 AM

Quote:

Originally Posted by mgayandk (Post 5292381)
i need to run a script at the boot up and wait for user input, i have write a script to init file and rc.local. scrypt run without waiting user input. what i need is, need a script which should wait until user input

Well, that is basically the same thing you said in your original post, and it still doesn't work that way.

What user input do you need exactly? Or are you referring to their login itself?

If you need to receive user specific input before user login... you can't reasonably do that.

If you need to run a script specific to one or more users, then you should put that into the user's shell init scripts, ~/.bash_profile for example. See man bash, or the man page for the intended user shell.

Welcome to LQ by the way!

unSpawn 12-30-2014 03:58 AM

Quote:

Originally Posted by mgayandk (Post 5292374)
i need to write a script to boot up process before login the user. and by using that script select the run level. what i need is when linux os boot ,it should wait until user give the user name and password. according to the username and password given by user the script will be select the run level.

One of the problems here is that we don't know what this "feature" (let's call it that) is to be used for: is it "just" a scripting exercise or is it a Real Life question (possibly by somebody lesser informed than usual to be making such requests?)... Secondly, and tying in closely with that, is the fact that the majority of Linux installations can (and will) boot unattended. This means that should you get your script to work and should the machine reboot without authorized personnel presence then you have a completely non-functioning machine. What I mean is that you should try and gauge the relative danger of implementing such features. Back to the start, if it's a scripting exercise then you should find out for your current Linux distribution and release where and when the default runlevel is or can be configured and then find out at which part of the boot process this default runlevel is actively looked for and switched to. Then you have to fetch the current runlevel and make an exception for (the equivalent of) runlevel 1 because you should not interfere with systems maintenance. Then figure out if file systems are mounted to be able to get to the credentials. I also need to point out that error handling is important because your script will be running as root user...


Unless you're a well-versed shell script writer I'm not expecting you to come up with the complete code but you have to try and show us. If you can't then at least start writing pseudo code until you can. If you're a budding shell script writer then start by reading. Here's some references to help get you started:

BASH intros:
http://www.gnu.org/software/bash/man...ode/index.html
http://www.tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
http://www.tldp.org/LDP/Bash-Beginne...tml/index.html

BASH scripting guides:
http://mywiki.wooledge.org/BashGuide
http://mywiki.wooledge.org/BashFAQ
http://mywiki.wooledge.org/BashPitfalls
# these are must reads so do read them!

Common questions / problems:
http://mywiki.wooledge.org/ParsingLs
http://mywiki.wooledge.orgDontReadLinesWithFor
http://mywiki.wooledge.org/UsingFind
http://mywiki.wooledge.org/Arguments
http://mywiki.wooledge.org/WordSplitting
http://mywiki.wooledge.org/Quotes

Also see:
http://www.linuxquestions.org/questi...l-links-35334/

The Advanced BASH scripting guide:
http://www.tldp.org/LDP/abs/html/

Bourne shell (compatibility):
http://www.grymoire.com/Unix/Sh.html



Quote:

Originally Posted by mgayandk (Post 5292374)
note: user name and password should be in separate text file. (..) users credentials should be stored in script

*Two important parts are getting requirements right and practising Safe Hex.

mgayandk 12-30-2014 05:09 AM

1 Attachment(s)
Quote:

Originally Posted by astrogeek (Post 5292391)
Well, that is basically the same thing you said in your original post, and it still doesn't work that way.

What user input do you need exactly? Or are you referring to their login itself?

If you need to receive user specific input before user login... you can't reasonably do that.

If you need to run a script specific to one or more users, then you should put that into the user's shell init scripts, ~/.bash_profile for example. See man bash, or the man page for the intended user shell.

Welcome to LQ by the way!

actually what i need is, im need to authenticate user without involving operating system login prompt. that is my research. no matter matter how many users , even one user that is enough to my research.

ex: user name = gayan
run level = 1
1. when boot up process run it should wait for user name -> then i enter the user name--> os should run in run level 1


user name = manitha
run level = 2
2. when boot up process run it should wait for user name -> then i enter the user name--> os should run in run level 2


my real requirement has been attached

unSpawn 12-30-2014 05:53 AM

The title and contents of your initial post do not match what you want to do. Next time please be so good as to share ALL relevant information up front. The easiest way to get two-factor auth going would be to hook it into full disk encryption or look at the OpenSC project as both have layed the groundwork already and are tried and true methods.

veerain 12-30-2014 07:38 AM

Runlevels change for the entire system. i.e. all users. If you want that only one user runs is present at a time then you should use own your runscripts for the init system. Many init systems are there.

1) Runit

2) S6

3) Perp

4) Daemontools

5) Sysvinit

and others.

Note: Most distro are not that easy to modify.


All times are GMT -5. The time now is 08:01 PM.