LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to wait at login prompt till the user press enter (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-wait-at-login-prompt-till-the-user-press-enter-4175523898/)

sindh 10-31-2014 07:05 AM

How to wait at login prompt till the user press enter
 
Hi ,


I am using run level 3 and added my own script in runlevel 3.

The script contains the line as the last line.
runmyscript.sh 2>&1 | tee /home/bootlog.txt &


During reboot, the above process will run as a separate process and will give a banner at the end that running the script is successful.

But the problem is, I am not getting the banner. As soon the script starts to run, getting the login prompt as below.

localhost login:



My requirement is, when the process starts running, it should display the output of the script till the user press enter.
When the user press enter, the script should run in background and give login prompt.

pls help me in this.

I tried different ways, like tail the bootlog, and sleep command.

rtmistler 10-31-2014 01:09 PM

Please post your script or a representative example of the script because what you describe isn't too intuitive. If you're running a script from the init.d as part of system initialization, then likely stdout is not being directed to a particular user's terminal. If you wish to run a script everytime any user logs in, or certain users, then you can modify the global profile or the specific profiles per user and then cause the script to run.

At the very least post the specific actions you've taken, like: Modified <filename> a sample echo of "This is running" would be sufficient. Right now it's unclear what you've tried.

jpollard 10-31-2014 01:48 PM

It sounds more like you want the script to be running BEFORE login.

Part of the problem is that getty/agetty initializes the terminal and provides the "login" prompt.

Now you can get around this by forcing the system to run something instead of getty/agetty - but that something will have to initialize the terminal, do the output, wait for the response... and then exec the login.

It also might be better to tell us what problem/requirement you are trying to solve.

sindh 11-03-2014 06:26 AM

Thank you very much for your replies.

For clarity, let me give additional info.

runmyscript.sh --> I need to run this script on linux which will load my binaries.
I am able to load this binaries on linux at boot time also.

My requirement is, I should be able to see the logs while running this script, also I need to redirect this output to some logs.

I used the below script to do it.
runmyscript.sh 2>&1 | tee /home/bootlog.txt &

Pls find my observations in Bare metal setup CIMC. - BASH shell

1. Loaded binaries
2. Got login prompt while the script is running - But script output is displayed even after that.
3. Also logs are available after booting



On virtual machine, used VNC viewer -BASH shell

1. Loaded binaries
2. Got login prompt while the script is running - Script is executed, but script output is not displayed
3. Logs are available after booting

I need the same behavior for virtual machine as BM setup
Pls let me know, if I missed anything to provide.

Thank you

rtmistler 11-03-2014 07:22 AM

Still not clear on what you're trying to do. I would not invoke with "2>&1 | tee".

I'd break this down into "debug output" and "intentional announcements".

As far as debug output. I wrote a blog about debugging bash scripts and covered my take on that here, and that entry covers much more scope beyond just output redirection.

What I prefer to do within the script is to use echo and ">" or ">>" redirectors to create and append to a log file. I also write the script where I check the return values from system commands, by checking the return variable $?. I've found that seeing stdout and stderr in cases of system call failures is way less useful to me than actually checking the result. What ends up going into my log file is debug of my own design where I report on what worked, what didn't, and the progress of my script; until I refine it to be what I want/need. I've also found that even if I do see stdout/stderr that it usually doesn't fully help me. Great, I know I have an error, but what I more need to know is what I gave to the system command. Because the "garbage in-garbage out" rule is usually true. It's great to know that a system command failed and what it's complaint is, but usually the problem is that what I gave it wasn't exactly what I "thought" I gave it. And I can't tell that by looking at stdout/stderr, but instead at an echo I made myself stating, "Calling .... with arguments ... and ..." Just my $0.02 there.

Sorry but I don't have much on the "intentional announcements" side of things. I know you can send a message to a terminal or a user, like the system can send an announcement like "System is rebooting", or "Hey Joe" to all terminals. I long ago played with that, a'la joking at peers by causing announcements to go to their terminals. First time that ends up going to the wrong person ... well that stops the workplace fooling around. :(

jpollard 11-03-2014 07:31 AM

Your observation depends on how the terminal is setup.

In the bare machine it is done external to the software as the physical devices exist.

In the virtual machine, they get simulated. Now whether they get created on demand depends on the support for the VM. It is even possible they don't get initialized (as in the device doesn't work until after getty/agetty sets the parameters). This could explain why the output doesn't get displayed. Since the logs are a separate output from the tee as stdout, it is even possible that stdout is effectively /dev/null.

sindh 11-18-2014 03:12 AM

Thank you all for your quick help.

My grub file goes like this.
title myProject (3.10.11)
root (hd0,0)
kernel /vmlinuz-3.10.11 ro root=/dev/mapper/VolGroup-lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/lv_swap SYSFONT=latarcyrheb-sun16 crashkernel=auto rd_LVM_LV=VolGroup/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM scsi_mod.scan=async console=tty0 console=ttyS0
initrd /initramfs-3.10.11.img



Changing the order of console=tty0 console=ttyS0 fixed the issue.

Thank you.


All times are GMT -5. The time now is 08:30 AM.