LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-31-2014, 07:05 AM   #1
sindh
LQ Newbie
 
Registered: Aug 2014
Posts: 28

Rep: Reputation: Disabled
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.
 
Old 10-31-2014, 01:09 PM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
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.

Last edited by rtmistler; 10-31-2014 at 01:10 PM.
 
Old 10-31-2014, 01:48 PM   #3
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
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.
 
Old 11-03-2014, 06:26 AM   #4
sindh
LQ Newbie
 
Registered: Aug 2014
Posts: 28

Original Poster
Rep: Reputation: Disabled
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
 
Old 11-03-2014, 07:22 AM   #5
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
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.
 
Old 11-03-2014, 07:31 AM   #6
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
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.
 
Old 11-18-2014, 03:12 AM   #7
sindh
LQ Newbie
 
Registered: Aug 2014
Posts: 28

Original Poster
Rep: Reputation: Disabled
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Ubuntu login circle: type userid+p/w, wait a few seconds, returns to login prompt Dart Linux - Newbie 2 10-21-2013 02:33 PM
[SOLVED] No prompt for root password after attempting to enter single user mode infinite_scale Linux - Newbie 3 07-30-2011 09:51 AM
unable to resume from s2disk till I press Alt+PrtSc+R+E adityavpratap Linux - Laptop and Netbook 2 07-07-2011 10:49 PM
how do i scan a character from keyboard without the user having to press enter rasika Programming 6 02-11-2010 08:54 PM
Can't wait 'till July 5th to the 8th! colinstu General 10 06-13-2007 12:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration