how to take input at the startup script!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to take input at the startup script!!
# 1  
Old 02-28-2008
how to take input at the startup script!!

Hi all,

I am trying to modify a startup script...
The problem is that i am unable to figure out how to take inputs from the user at the startup screen and proceed with the processing accordingly...

Eg:
$ echo "this is a test" (typically this would produce the output)...
$ echo "this is a test" >/dev/msglog (this is used to produce the same output before shell is initialized)...

Similarly,i wanted to know the equivalent for the read statement!!!!
eg:
$ read x (usually reads <something> to variable x)
How can i incorporate the same at the startup??

thanks
# 2  
Old 02-29-2008
something like that ?
Code:
#!/bin/sh
INPUT_STRING=hello
while [ "$INPUT_STRING" != "bye" ]
do
  echo "Please type something in (bye to quit)"
  read INPUT_STRING
  echo "You typed: $INPUT_STRING"
done

P.S. I found this on the net.
# 3  
Old 02-29-2008
So you are trying to do something before the system is started?
Possibly
Code:
read var

should work, if not then you could try
Code:
</dev/stty0

or something similar. But in my opinion this is not a good thing.
# 4  
Old 03-01-2008
Yeah something like this, but this is done all the while isnt it??

Eg: During the installation of solaris ,one of the first few screens have this option to choose which type of an installation is to be done!!!
like
solaris express developer edition
solairs exprees

something like that....
And according to what the user types in the corresponding installation starts up...
SO here the case statement will be used(i supposeSmilie )...
and again the shell isnt initialised yet..
So in this case how does the proper script be recognised...

If i can know how the user input is read here..that would be enough!!!
# 5  
Old 03-02-2008
I'm not understanding if you want to allow a user to give your script a flag/variable at the command line, or if you want an interactive script with a menu. Either way:
Passing a flag/variable to a script, simplest way, in the script just do:
Code:
myVariable=$1

So, when you run the script on the command line, you'd type:
Code:
# script.ksh  <myVariable>

The elements in the command line are counted much like the elements in an array, so when you type the above command, script.ksh is $0 , myVariable is $1, whatever you'd type after myVariable is $2, etc.. Quick example:
Code:
# cat script.ksh
myVariable=$1
yourVariable=$2
echo $yourVariable $myVariable

# script.ksh world hello
hello world

You could use $1 in a case statement for an rc startup script, like this:
Code:
# cat script.ksh
case $1 in
         start) echo starting;;
          stop) echo stopping;;
             *) echo "don't understand anything but stop and start; doing nothing";;
esac

In the case of an interactive script, when you present users with choices, much like your example of the Solaris installation, if the choices are many and require many words to explained, echo a numbered menu so the user only has to input a number rather than a whole sentence:
Code:
# cat script.ksh
echo "Press 1 for start"
echo "Press 2 for stop"
read myVariable?"Enter your choice: "
case $myVariable in
         1) echo starting;;
         2) echo stopping;;
         *) echo "don't understand anything but 1's and 2's; doing nothing";;
esac


Last edited by System Shock; 03-02-2008 at 11:12 AM..
# 6  
Old 03-02-2008
Quote:
Originally Posted by adderek
But in my opinion this is not a good thing.
I have the same opinion. To the kernel, the definition of a daemon is a process with no controlling terminal. Daemons show up with a ? in the tty field on most implementations of ps. When a daemon opens a tty, that tty becomes it's controlling terminal. It is no longer a daemon nor will any child processes be daemons. As one example of the many problems this will cause, if you type a control c on that terminal all processes with that controlling will get an INTR unless they are ignoring that signal.

You can avoid this by forking a subprocess to open the terminal, do the tty io, pass the data back to the parent via a file or pipe, and then exit. You must also ensure that this is completed prior to any login prompt appearing on the terminal.

This is why daemons fork to write a message on the console. Becoming a daemon again is not possible, but with the right sequence of operations including several forks(), a process can arrange for a descendant process to be created as a daemon.

Avoiding the non-daemon trap will still leave the problem that the user must be present at reboot time, but at least the system should be working.
# 7  
Old 03-02-2008
Thanks a lotSmilieSmilie

I think i can solve the issue with this...
If not i will surely get back...

Thanks again
Smilie Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Startup script

I can't quite find a clear answer on how to properly write a start up script. Does anybody have any ideas?? (3 Replies)
Discussion started by: Huitzilopochtli
3 Replies

2. Shell Programming and Scripting

Apache tomcat startup script not booting at startup.

I copied the script from an AskUbuntu post - #!/bin/bash ### BEGIN INIT INFO # Provides: tomcat7 # Required-Start: $network # Required-Stop: $network # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start/Stop Tomcat server ### END INIT INFO ... (14 Replies)
Discussion started by: Hijanoqu
14 Replies

3. Shell Programming and Scripting

Startup and shutdown script

Hi all, I'm writing a script to stop & start oracle: su - oracle -c "sqlplus / as sysdba" -c "shutdown immediate">> ${log} 2>&1 The {log} refers to the log file. The part in bold gives error: /usr/sbin/shutdown: Only root can run /usr/sbin/shutdown Pls suggest how to correct this. ... (5 Replies)
Discussion started by: frum
5 Replies

4. Shell Programming and Scripting

Script to delete files with an input for directories and an input for path/file

Hello, I'm trying to figure out how best to approach this script, and I have very little experience, so I could use all the help I can get. :wall: I regularly need to delete files from many directories. A file with the same name may exist any number of times in different subdirectories.... (3 Replies)
Discussion started by: *ShadowCat*
3 Replies

5. AIX

startup script

Hi I need the below script to be started whenever I reboot my aix server ? #cat cdbegin /cdirect/cdunix/ndm/bin/cdpmgr -i /cdirect/cdunix/ndm/cfg/cbspsdb01/initparm.cfg Please suggest how to add this to the startup ? (2 Replies)
Discussion started by: samsungsamsung
2 Replies

6. UNIX for Dummies Questions & Answers

Startup Script Somewhere ?

Hello there! I need help. Everytime I login to my ssh, i see this: -bash: .export: command not found -bash: .export: command not found -bash: .export: command not found -bash: .export: command not found any help ? thanks (0 Replies)
Discussion started by: fbauto1
0 Replies

7. AIX

run script at startup

I am using AIX 5.3 in P6 machine. I have a script "test.sh", when i run it manually it runs properly. I want to run the script automatically when system starts. I kept the script in /etc/rc.d/init.d and also in /etc/rc.d/rc2.d but it is not working. Do i have to write it in inittab instead of... (1 Reply)
Discussion started by: pchangba1
1 Replies

8. HP-UX

Executing a script at startup

Hi, I want a script to execute as soon as a user logs in(instead of directing to his home directory). i know that i have to mention the path of script in the user's .profile to execute this, but not sure where and what to edit. I just tried and was unsuccesful. Kindly provide the code that i... (4 Replies)
Discussion started by: sridharr83
4 Replies

9. Shell Programming and Scripting

Startup script

New in Unix, I am adding a line "route add 57.14.y.y 57.14.x.x" every day after rebooting the system. Where can I add the line so during boot up (the system is re-started every day by design (???) the line is executed? (I tried the /etc/rc2.d/S90 but for some reason the line needs to be added... (2 Replies)
Discussion started by: texaspanama
2 Replies
Login or Register to Ask a Question