- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Terminal or not Terminal
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2003 01:26 AM
тАО12-18-2003 01:26 AM
I have a couple scripts that can be run online or as a batch There are some interactive things that should be entered when interactive and default when batched. I know there is a command that will tell me this but I can not remember what it is.
something like
if [ "$THIS_IS_A_TERMINAL" = "YES" ]
then
echo "do something"
else
echo "let the computer do something else"
fi
Can you help?
Marty
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2003 01:31 AM
тАО12-18-2003 01:31 AM
Re: Terminal or not Terminal
RESULT=`tty`
if [ $RESULT = 0 ]
then
echo "do something"
else
do something that isn't an echo becuase we haven't go a terminal to write to :)
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2003 01:34 AM
тАО12-18-2003 01:34 AM
Re: Terminal or not Terminal
then
echo "INTERACTIVE SESSION"
fi
Massimo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2003 01:34 AM
тАО12-18-2003 01:34 AM
Re: Terminal or not Terminal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2003 01:37 AM
тАО12-18-2003 01:37 AM
Re: Terminal or not Terminal
RESULT=`tty 2>&1 | grep '^/dev/'`
if [ -n "$RESULT" ]
then
# You have a terminal
else
# No terminal, run unattended
fi
You could also remove the RESULT var:
if tty 2>&1 | grep -q '^/dev/'
then
# Run attended
else
# Run unattended
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2003 01:56 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2003 02:15 AM
тАО12-18-2003 02:15 AM
Re: Terminal or not Terminal
if [[ -t 0 && -t 1 && -t 2 ]]
then
echo "Stdin (0), Stdout (1), and Stderr (2) are tty devices"
fi
Isn't Stdin (0), Stdout (1), and Stderr (2)always available?
It works!
Marty
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2003 02:19 AM
тАО12-18-2003 02:19 AM
Re: Terminal or not Terminal
Give up and give A.Clay the bunny :)
Anything with the standard input closed, is, by definition, not realy attached to a terminal and therefore the test is perfectly valid and smarter than the other suggestions (especially mine).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2003 02:27 AM
тАО12-18-2003 02:27 AM
Re: Terminal or not Terminal
The -s option
inhibits printing of the terminal path name and any diagnostics,
providing a means to test only the exit code.
NO POINTS PLEASE.
Massimo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-18-2003 02:28 AM
тАО12-18-2003 02:28 AM
Re: Terminal or not Terminal
I already have the scrapt installed in many places. Tested and works great.
I like the simple things.
Thank you and happy holidays.
Marty