LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-05-2011, 08:40 AM   #1
dimothy
LQ Newbie
 
Registered: Jun 2010
Posts: 10

Rep: Reputation: 0
Problems with script redirection


Am having issues getting the output from a script to be logged in a file. I need the script to output both the stderr and stdout to the same text file.

At present I have the following script:

Code:
#!/bin/bash
echo TR3_1 > printers.txt
snmpget -v 1 -c public 10.168.**.* SNMPv2-SMI::mib-2.43.10.2.1.4.1.1 &>> printers.txt
echo TR3_10 >> printers.txt
snmpget -v 1 -c public 10.168.**.* SNMPv2-SMI::mib-2.43.10.2.1.4.1.1 &>> printers.txt

but when I run it I get the follwing error:

Code:
./printersrh.sh: line 3: syntax error near unexpected token `>'
./printersrh.sh: line 3: `snmpget -v 1 -c public 10.168.**.* SNMPv2-SMI::mib-2.43.10.2.1.4.1.1 &>> printers.txt'
I was under the impression that the & symbol was used to output stderr while the double arrow was used to append to a file?

Have I missed something here?

Last edited by dimothy; 08-05-2011 at 08:43 AM.
 
Old 08-05-2011, 08:58 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
According to the GNU Bash Reference Manual (section 3.6.5 Appending Standard Output and Standard Error): "The format for appending standard output and standard error is: &>>word" so what you used should work.

Perhaps you are not using bash, perhaps you are using an early version of bash which did not support this usage (not sure about that). Does it work if you use 2>>printers.txt >>&2 ? What is the output of bash --version ?
 
1 members found this post helpful.
Old 08-05-2011, 09:07 AM   #3
dimothy
LQ Newbie
 
Registered: Jun 2010
Posts: 10

Original Poster
Rep: Reputation: 0
good call. ran a bash --version and it is using version 3 something. loaded up an ubuntu server i have for something else and the script runs fine (it is using version 4). think that might be the end of that then! thanks again
 
Old 08-05-2011, 09:54 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
Unfortunately I do not know of a list of bash features and which versions they were introduced by; it would be nice to confirm when the &>> operator was introduced.

Threads can be marked SOLVED via the Thread Tools menu.
 
1 members found this post helpful.
Old 08-08-2011, 05:00 AM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Quote:
Originally Posted by catkin View Post
Unfortunately I do not know of a list of bash features and which versions they were introduced by; it would be nice to confirm when the &>> operator was introduced.
4.0-alpha

http://mywiki.wooledge.org/BashFAQ/061
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] shell script redirection -- a question SaintDanBert Linux - Software 2 04-15-2010 12:42 PM
FTP in a Bash Shell Script redirection sleepyhomme Programming 2 05-02-2007 12:53 PM
Website redirection script PdotROSS Linux - Networking 1 09-09-2005 01:39 PM
shell script output redirection goral.j Programming 3 01-27-2005 06:34 AM
I/O redirection in a shell script gladeiator Programming 1 11-27-2003 02:35 PM


All times are GMT -5. The time now is 10:46 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration