LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 12-30-2009, 01:24 PM   #1
izghitu
Member
 
Registered: Oct 2005
Location: localhost.localdomain
Distribution: CentOS
Posts: 109

Rep: Reputation: 16
start up script


Hi,

I have Ubuntu 9.10

I want to set up a start up script that is executed last when the server boots and asks for user input/performs some tasks.

I've added the script to /etc/init.d/local and made it executable using:
update-rc.d local defaults 80

When the server boots, I do not see anything on the screen and no user input is requested although the script is executed.

If I add a reboot to the script to the end of the file after user input requests, the server is rebooted regardless of the "read" commands.

Am I doing something wrong?

Please help

Thanks
 
Old 12-30-2009, 04:15 PM   #2
blackhole54
Senior Member
 
Registered: Mar 2006
Posts: 1,896

Rep: Reputation: 61
I've never tried this but I am guessing the script is not connected to any terminal. In that case the read command would generate an error and the script would continue executing (which is consistent with what you report about the reboot command).

Assuming at that point in the boot the display is /dev/tty1, you could try redirecting I/O using an exec command at the beginning of the script:

Code:
exec > /dev/tty1 2>&1 < /dev/tty1

Just as a general comment about troubleshooting situations like this where you can't directly observe the script, I sometimes find it useful to redirect stderr to a file and enable tracing (removing those commands after I have it working). Then I can check the file after the fact to see what happened:

Code:
exec 2> /tmp/somefilename
set -x

ONE CAVEAT: The last I checked, Ubuntu used dash (instead of bash) for /bin/sh. I just checked the man page and I think the above will work in dash but am not absolutely certain. If not, you could (if you haven't already) specify /bin/bash instead of /bin/sh for your script.
 
1 members found this post helpful.
Old 12-31-2009, 02:40 AM   #3
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
also be careful when using exec.. with that you could replace the process of the shell with the command and when the command finishes, it's the end of the line.
 
Old 12-31-2009, 02:46 PM   #4
blackhole54
Senior Member
 
Registered: Mar 2006
Posts: 1,896

Rep: Reputation: 61
Quote:
Originally Posted by konsolebox View Post
also be careful when using exec.. with that you could replace the process of the shell with the command and when the command finishes, it's the end of the line.
Absolutely. The form of the exec command I showed doesn't have a target command so it just redirects input and output for the current shell.
 
Old 01-01-2010, 05:36 AM   #5
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
Quote:
Originally Posted by blackhole54 View Post
Absolutely. The form of the exec command I showed doesn't have a target command so it just redirects input and output for the current shell.
Sorry I forgot to quote. I wasn't really referring to your post. Obviously exec can also be used that way... But the OP mentioned that some parts of the script did not ask for user input so I thought maybe he accidentally used exec to execute 1 of the commands. I got the idea when you made that post though.
 
Old 01-01-2010, 06:37 AM   #6
izghitu
Member
 
Registered: Oct 2005
Location: localhost.localdomain
Distribution: CentOS
Posts: 109

Original Poster
Rep: Reputation: 16
The
Code:
exec > /dev/tty1 2>&1 < /dev/tty1
thing worked

thanks a lot for your help
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
start script bash when system start,stop,reeboot, how ?? melmar Linux - General 4 12-10-2009 06:58 AM
Bash script to start another script when USB is inserted? linus72 Linux - Newbie 1 04-16-2009 05:19 AM
ssh - using variables in call to start remote script from local script babag Linux - Networking 2 06-03-2008 04:50 PM
Start a script after GDM autologin, don't quit when script finishes Plastech Linux - Newbie 2 05-29-2007 10:15 AM
How to start a Tcl/Tk script by simply invoking the script file itself ? cyu021 Programming 2 10-10-2004 11:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 09:40 AM.

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