tty command failing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting tty command failing
# 1  
Old 11-18-2009
tty command failing

We have script like this in the .bash_profile..

Code:
#-# determine if session is interactive or in background
if [[ "$(/usr/bin/tty -s)" -eq 0 ]]; then
   while true; do
    	read -p "Do you wish to load profile yes or no?" yn
    	case $yn in
        	[Yy]* ) source /opt/oracle/.profile; break;;
       		[Nn]* ) break;;
        	* ) echo "Please answer yes or no.";;
    	esac
   done
else
 echo "session running in background returns $?" > /tmp/D.txt
fi

what we are trying to do is , if it 's interective session load profile other wise ignore it ( some times we will restart the system and if it's not interective) . This is code looks good and not working . any ideas ....

Thanks
# 2  
Old 11-19-2009
Quote:
Originally Posted by talashil
We have script like this in the .bash_profile..

Code:
#-# determine if session is interactive or in background
if [[ "$(/usr/bin/tty -s)" -eq 0 ]]; then


The tty -s command doesn't output anything, so there is nothing to compare. You want to compare the return code, not the output:

Code:
if tty -s; then

Better yet, you can use the test command which is a shell builtin:

Code:
if test -t 0 ; then

Quote:
Code:
   while true; do
    	read -p "Do you wish to load profile yes or no?" yn
    	case $yn in
        	[Yy]* ) source /opt/oracle/.profile; break;;
       		[Nn]* ) break;;
        	* ) echo "Please answer yes or no.";;
    	esac
   done
else
 echo "session running in background returns $?" > /tmp/D.txt
fi

what we are trying to do is , if it 's interective session load profile other wise ignore it ( some times we will restart the system and if it's not interective) . This is code looks good and not working . any ideas ....

Thanks
# 3  
Old 11-19-2009
Thankyou
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Python: Redirecting to tty and reading from tty

In bash, you can do something like this: #!/bin/bash echo -n "What is your name? " > /dev/tty read thename < /dev/tty How can I do the same in python? I have a python script that has the following content: #!/usr/bin/python2.7 import getpass import sys import telnetlib import... (2 Replies)
Discussion started by: SkySmart
2 Replies

2. Shell Programming and Scripting

How to auto correct a failing command?

If a command is not found, e.g. nawk, this is how I fix the problem ] && NAWK=/usr/bin/gawk ] && NAWK=/usr/bin/nawk ] && NAWK=/usr/bin/awkI use $NAWK an the set the appropriate value based on the system it runs. How can I implement a similar fix for a command found but illegal argument.... (6 Replies)
Discussion started by: mohtashims
6 Replies

3. UNIX for Advanced & Expert Users

While trying to load .so file manually using command its failing

Hi all, I am newbie to linux environment. I was trying to run an .so file manually which in turn call a method in bin folder. Command given, XXX_MODULES=libxxx.so /opt/servicename/bin/methodname -Le -c /opt/servicename/etc/methodname/methodname.conf -n -C -t -m "" When i tried to execute... (1 Reply)
Discussion started by: sharathpadman
1 Replies

4. UNIX for Dummies Questions & Answers

While trying to load .so file manually using command its failing

Hi all, I am newbie to linux environment. I was trying to run an .so file manually which in turn call a method in bin folder. Command given, XXX_MODULES=libxxx.so /opt/servicename/bin/methodname -Le -c /opt/servicename/etc/methodname/methodname.conf -n -C -t -m "" When i tried to... (1 Reply)
Discussion started by: sharathpadman
1 Replies

5. Shell Programming and Scripting

Connect (SSH) to Windows server via Linux server through a script and passing command.. but failing

I am trying to connect to Windows server via Linux server through a script and run two commands " cd and ls " But its giving me error saying " could not start the program" followed by the command name i specify e g : "cd" i am trying in this manner " ssh username@servername "cd... (5 Replies)
Discussion started by: sunil seelam
5 Replies

6. Shell Programming and Scripting

For loop failing cd command

Hi guys, i've wrote the following loop; for i in `ls` do cd $i/host cat "xxxx.txt" |grep "yyyy" >> zzzz.txt done I have a set of folder with different name and i need to extract a value from a file contained in the host subfolder ( that is present in each folder). When i run... (4 Replies)
Discussion started by: cecco16
4 Replies

7. Shell Programming and Scripting

Extract tty from ps command

When I try to extract tty from ps command , at time we get output , at times we dont. for eg i executed below quesry continulusly for some time,Actually i feel its because sometime pid allocated has some additional space at begining which causes this issue. ->ps | grep "/-ksh" | tail -1 | cut -f4... (2 Replies)
Discussion started by: lalitpct
2 Replies

8. UNIX for Advanced & Expert Users

tty changes?

I am not sure if I am using the correct terminology but somehow my tty keeps changing on me. The man pages are confusing to me on what exactly the tty is. This is what I see when I run the tty command. Could anyone explain why my tty keeps changing? ~ $ tty /dev/pts/1 ~ $ tty /dev/pts/0 (6 Replies)
Discussion started by: cokedude
6 Replies

9. Solaris

Command to redirect console to my tty?

Is there a utility built into Solaris that will allow me to see console messages from a tty? I've done a search and see that this is possible through software like ILOM, but I'm looking for a method to do this with built in utilities. For example, on AIX, I can use swcons `tty` (6 Replies)
Discussion started by: makodarear
6 Replies

10. HP-UX

dd command failing

I am new to HP-UX. I have an 8GB drive that is my root drive, contained in a Volume Group. I would like to clone that drive to another drive, which is 18.4GB. The other drive is not in a volume group. I am using this simple command:# dd if=/dev/dsk/c0t6d0 of=/dev/dsk/c0t5d0The command... (4 Replies)
Discussion started by: emsecrist
4 Replies
Login or Register to Ask a Question