- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Output redirection help in ksh script
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
Forums
Discussions
Discussions
Discussions
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
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
04-25-2006 03:32 AM
04-25-2006 03:32 AM
{ fbackup $backup_type -u $verbose_option $nfs_option -g $graph_file $index_opt
} $logfile 1> $logfile
Here is what it looked like when it ran using (ksh -x scriptname )
+ 0< /bow/resp + fbackup -0 -u -n -g /bow/bowgraph -I /bow/backuplogs/25Apr06.full -c /bow/backup_config -d /bow/fbackupfiles/datesm (*output cut off*)
fbackup(1004): session begins on Tue Apr 25 11:01:25 2006
fbackup(3203): volume 1 has been used 7 time(s)
fbackup(3024): writing volume 1 to the output file /dev/rmt/0m
fbackup(3009): WARNING: File number 72630 (/orabackup/oradata/ediprod/redologs/ediprod_redo2.dbf)
was not successfully backed up
fbackup(3055): total file blocks read for backup: 25546882
fbackup(3056): total blocks written to output file /dev/rmt/0m: 26110005
fbackup(1030): warnings encountered during backup
I wanted the above output to go into the file pointed to by $logfile. I pointed standard output and stantard error to $logfile which was empty after the job ran. $logfile and all other variables in the above line are defined earlier in the script.
Any suggestions?
Solved! Go to Solution.
- Tags:
- redirect
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2006 03:37 AM
04-25-2006 03:37 AM
Re: Output redirection help in ksh script
} &1 1> $logfile
live free or die
harry d brown jr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2006 04:23 AM
04-25-2006 04:23 AM
Re: Output redirection help in ksh script
you are using different redirections to the same file - which one will win?
Configure the output an error stream instead:
1) use different files for stdout and stderr
{
cmd
} >outfile 2>errorfile
2) Redirect one stream to the other
{
cmd
} >outfile 2>&1
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2006 04:29 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2006 04:53 AM
04-25-2006 04:53 AM
Re: Output redirection help in ksh script
Order is important here, too!
Run this script snippet:
# cat .redir
#!/usr/bin/sh
echo "from stdout"
print -u2 "from stderr"
exit 0
...Do this:
# ./redir 2>&1 1> /redir.log
from stderr
# cat redir.log
from stdout
Now:
# ./redir 1> /redir.log 2>&1
# cat redir.log
from stdout
from stderr
In the second case you achieve what you want. In the first case, STDERR was assigned to your terminal *and* then STDOUT was assigned to the file.
Regards!
...JRF...
#
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2006 05:12 AM
04-25-2006 05:12 AM
Re: Output redirection help in ksh script
Actual code:
{ fbackup $backup_type -u $verbose_option $nfs_option -g $graph_file $index_opt
} &1 1>$logfile
Actual output
+ 0< /bow/resp 2>& 1 + fbackup -0 -u -n -g /bow/bowgraph -I /bow/backuplogs/25Apr06.full -c /bow/backup_config -d /bow/fbackupfilesm
fbackup(1004): session begins on Tue Apr 25 13:04:09 2006
fbackup(3203): volume 1 has been used 8 time(s)
fbackup(3024): writing volume 1 to the output file /dev/rmt/0m
fbackup(3055): total file blocks read for backup: 25676534
fbackup(3056): total blocks written to output file /dev/rmt/0m: 26241878
The output file is completely empty. Did I miss something?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2006 05:16 AM
04-25-2006 05:16 AM
Re: Output redirection help in ksh script
>$logfile 2>&1
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2006 05:17 AM
04-25-2006 05:17 AM
Re: Output redirection help in ksh script
With regard to your second question, see my post just above: "Order is important here, too!"
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2006 05:24 AM
04-25-2006 05:24 AM
Re: Output redirection help in ksh script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2006 07:13 AM
04-25-2006 07:13 AM
Re: Output redirection help in ksh script
{ fbackup $backup_type -u $verbose_option $nfs_option -g $graph_file $index_option -c $config_file -d $fbackupfiles -f $device
} $logfile 2>&1
fbackup(1004): session begins on Tue Apr 25 15:02:37 2006
fbackup(3203): volume 1 has been used 9 time(s)
fbackup(3024): writing volume 1 to the output file /dev/rmt/0m
fbackup(3055): total file blocks read for backup: 21220083
fbackup(3056): total blocks written to output file /dev/rmt/0m: 21787601
Still no output in the file. I will now try the method given by Rodney.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2006 07:22 AM
04-25-2006 07:22 AM
Re: Output redirection help in ksh script
If so then the syntax requires a ; before the closing right curly bracket.
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2006 07:29 AM
04-25-2006 07:29 AM
Re: Output redirection help in ksh script
{ fbackup $backup_type -u $verbose_option $nfs_option -g $graph_file $index_opt
} $logfile 2>&1
+ fbackup -0 -u -n -g /bow/bowgraph -I /bow/backuplogs/25Apr06.full -c /bow/backup_config -d /bow/fbackupfiles/dates -f /dev/rmt/0m
fbackup(1004): session begins on Tue Apr 25 15:18:36 2006
fbackup(3203): volume 1 has been used 10 time(s)
fbackup(3024): writing volume 1 to the output file /dev/rmt/0m
fbackup(1102): WARNING: unable to stat file /entsys/tmp/cos.003354981498422125.1385.6
fbackup(3005): WARNING: file number 33092 was NOT backed up
fbackup(1030): warnings encountered during backup
fbackup(3055): total file blocks read for backup: 21283397
fbackup(3056): total blocks written to output file /dev/rmt/0m: 21851691
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2006 07:50 AM
04-25-2006 07:50 AM
Re: Output redirection help in ksh script
As Rodney noted, a a final semicolon is required after the last statement in curly braces. I agree that you last post seems correct otherwise. That aside, I use this in one of my scripts:
# ( /usr/sbin/fbackup -f $FB_DEV -0 -u -v -g $FB_GRF -V $FB_VOL -c $FB_CNF 2>&1 ; echo $? > $FB_XIT ) | tee -ia $FB_LOG
The approach I that I took here uses a sub process (and yes, there is not a semicolon in this syntax) but writes STDOUT and STDERR to ${FB_LOG} as well as the terminal.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2006 07:58 AM
04-25-2006 07:58 AM
Re: Output redirection help in ksh script
1>$logfile 2>&1
This fbackup command is inside a script and I am trying to save the output and/or error/warnings in the $logfile. I am apparently not seeing what is wrong with the syntax.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2006 08:05 AM
04-25-2006 08:05 AM
Re: Output redirection help in ksh script
2>&1 >> $logfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2006 08:11 AM
04-25-2006 08:11 AM
Re: Output redirection help in ksh script
Thanks for all the help and for putting up with my typo.