LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris, OpenSolaris, OpenIndiana, and illumos.
General Sun, SunOS and Sparc related questions also go here. Any Solaris fork or distribution is welcome.

Notices


Reply
  Search this Thread
Old 08-24-2009, 07:49 AM   #1
jcllings
Member
 
Registered: Jun 2004
Location: Tacoma, WA
Distribution: Ubuntu
Posts: 37

Rep: Reputation: 15
BASH I/O Redirection on Solaris?


So I have a bash script that does

#Send standard out to a file.
exec > ${FILENAME}

#...
#do stuff that is dumped to a file.
#...

#Restore standard out to the screen.
exec > /dev/tty

On Linux one would use "exec > /dev/tty" to restore the standard out to the screen but I can't seem to get this to work. Am I doing something wrong?


Jim C.
 
Old 08-24-2009, 08:11 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
It works for me, both on OpenSolaris 2008.11 and Solaris SPARC 5.8. Which system are you running on and which bash version?
 
Old 08-24-2009, 09:32 AM   #3
jcllings
Member
 
Registered: Jun 2004
Location: Tacoma, WA
Distribution: Ubuntu
Posts: 37

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by colucix View Post
It works for me, both on OpenSolaris 2008.11 and Solaris SPARC 5.8. Which system are you running on and which bash version?
On the line with "exec > /dev/tty", I get:

line 32: /dev/tty: No such device or address

a grep shows line 32:

32:exec > /dev/tty

perms are:

[user@server ~ 489]$ ls -la /dev/tty; ls -la /devices/pseudo/sy@0:tty
lrwxrwxrwx 1 root other 26 Jul 30 2008 /dev/tty -> ../devices/pseudo/sy@0:tty
crw-rw-rw- 1 root tty 22, 0 Aug 24 10:13 /devices/pseudo/sy@0:tty

uname -a reports:

[user@server ~ 490]$ uname -a
SunOS server 5.10 Generic_138888-03 sun4u sparc SUNW,Sun-Fire-V245
[user@server ~ 491]$ bash -version
GNU bash, version 3.00.16(1)-release (sparc-sun-solaris2.10)
Copyright (C) 2004 Free Software Foundation, Inc.
[user@server ~ 492]$
 
Old 08-24-2009, 10:02 AM   #4
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
The system specifications are almost the same on my Sun SPARC, except I have older versions:
Code:
$ uname -a
SunOS server 5.8 Generic_108528-20 sun4u sparc SUNW,UltraAX-i2
$ bash -version
GNU bash, version 2.03.0(1)-release (sparc-sun-solaris)
Copyright 1998 Free Software Foundation, Inc.
$ ls -la /dev/tty
lrwxrwxrwx   1 root     other         26 Apr 28  2003 /dev/tty -> ../devices/pseudo/sy@0:tty
$ ls -la /devices/pseudo/sy@0:tty
crw-rw-rw-   1 root     tty       22,  0 Aug 24 15:09 /devices/pseudo/sy@0:tty
It works for me even if I redirect the standard output to the allocated pseudo-terminal, that is exec > /dev/pts/1. You can check yours using the tty command. Here's mine:
Code:
$ tty -l
/dev/pts/1
not on an active synchronous line
Hope this helps.
 
Old 08-24-2009, 10:50 AM   #5
jcllings
Member
 
Registered: Jun 2004
Location: Tacoma, WA
Distribution: Ubuntu
Posts: 37

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by colucix View Post
The system specifications are almost the same on
Code:
$ tty -l
/dev/pts/1
not on an active synchronous line
Hope this helps.
What I get from my script is:

not a tty
not on an active synchronous line

If executed from the command line, I get:

tty -l
/dev/pts/1
not on an active synchronous line

Is there a way that I can save off the file descriptor for standard out and then re-direct to it later?


Jim C.
 
Old 08-24-2009, 11:28 AM   #6
jcllings
Member
 
Registered: Jun 2004
Location: Tacoma, WA
Distribution: Ubuntu
Posts: 37

Original Poster
Rep: Reputation: 15
One thing I forgot to mention. The script in question is called by ssh from another machine.
 
Old 08-24-2009, 11:32 AM   #7
jcllings
Member
 
Registered: Jun 2004
Location: Tacoma, WA
Distribution: Ubuntu
Posts: 37

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by jcllings View Post
One thing I forgot to mention. The script in question is called by ssh from another machine.
Bingo! That was the problem. I have to use ssh -t to force a pseudo tty.
 
Old 08-24-2009, 02:03 PM   #8
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by jcllings View Post
Bingo! That was the problem. I have to use ssh -t to force a pseudo tty.
Well done!
 
  


Reply



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
BASH scripting I/O redirection error blinux1 Programming 13 03-18-2008 08:21 PM
Bash I/O redirection problem R00ts Programming 1 10-26-2006 07:50 PM
bash: socket redirection? Thinking Linux - Software 1 04-15-2006 12:20 PM
Bash redirection and subshells nx5000 Programming 2 11-03-2005 06:13 AM
Bash redirection being taken literally by programs R00ts Programming 13 05-26-2005 12:46 AM

LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris

All times are GMT -5. The time now is 12:35 PM.

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