LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   Logic - Am I running interactively or no? (https://www.linuxquestions.org/questions/linux-server-73/logic-am-i-running-interactively-or-no-4175602263/)

UltraPain 03-21-2017 08:14 AM

Logic - Am I running interactively or no?
 
Hi all,

I've found several hits in researching my issue, but none seem to touch on my exact issue. When logging into my RHEL 6 server as the oracle user (korn shell), .profile calls the oraenv script to set the environment, which prompts the user for input. I'm trying to write logic that says, in pseudo-code:

if this session is interactive, run oraenv
else, don't

Oracle delivers init scripts to start and stop oracle services on shutdown and startup. The scripts use the su - oracle -c blah syntax to stop and start oracle services, but because .profile calls oraenv, the system is prompted for input.

Thanks!

UltraPain 03-21-2017 01:51 PM

problem solved
 
the logic I used to resolve this is:

if tty -s ; then
my settings
fi

rtmistler 03-21-2017 01:54 PM

Usually there are already tests in startup scripts to determine if a login is interactive versus not. Either case, the old BASH tried and true has always worked for me:
Code:

if [ -z "$PS1" ]; then
        echo This shell is not interactive
else
        echo This shell is interactive
fi

Or the other form typically found in the .bashrc file:
Code:

case "$-" in
*i*)        echo This shell is interactive ;;
*)        echo This shell is not interactive ;;
esac


chrism01 03-23-2017 11:49 PM

There are some methods here http://www.tldp.org/LDP/abs/html/intandnonint.html


All times are GMT -5. The time now is 05:25 AM.