General :: Redirect Stdout/stderr Of Multiple Commands In One Shot?

Jun 3, 2011

I have several commands in a bash script, and in the middle of the script there are several commands whose output and error streams I want to redirect to a file. I think I could simply add '>> myfile.txt' to the end of every command, but is there a way to set it before that block of commands, then reset the streams to their original state at the end of that block?

View 1 Replies


ADVERTISEMENT

Programming :: Cannot Redirect All Stdout And Stderr Into File

May 12, 2009

I have a little complex Makefile system. A parent Makefile call dozens of Makefiles in subdirctories. And the subdirctory Makefile calles shell script to do real building. I want to grab all output this Makefile system generate. So, i employ "make 2>&1 > make.log". but not all output messages are filed into make.log. The message generated by sub-makefile called shell script cannot be recorded into make.log. And another curiouse thing is, if i launch "make 2>&1 > make.log" in a perl script, all output do be sent into make.log.

View 2 Replies View Related

General :: Script To Output Both The Stderr And Stdout To The Same Text File?

Aug 5, 2011

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

[Code].....

View 4 Replies View Related

General :: Redirect Stdin And Stderr To Another Terminal?

Jun 28, 2010

Is it possible to redirect stdout and stderr from one terminal say /dev/pts/2 to another /dev/pts/3?

I tried the following:

Code:
/dev/pts/2 2>&1 /dev/pts/3&

Then when I run a command the process stops.

View 4 Replies View Related

Software :: Bash Output Stderr To 2 Files And Stdout?

Apr 5, 2011

I want to output the stdout and stderr in a logfile,moreover i do want to log stderr also to a separate logfile, and print str to the screen I searched arround and tried:

Code:

$ command 2>&1 > log | tee -a log log.err

But then in log first the stdout appears, and then stderr.

View 1 Replies View Related

Software :: Get Stderr And Stdout Of A Program Into Separate Env Variables?

May 19, 2010

Code:

MY_STDOUT=`my-command`
MY_STDERR=`my-command >&2`

That is, i want to have to run my-command only once and get the same result. I've tried this:

Code:

YYY=$(XXX=`{ echo -n 111; echo 222 >&2; }` 2>&1); echo $XXX $YYY

where "{ echo -n 111; echo 222 >&2; }" is my-command. But it gives this output:

Code:

222
111

instead of "111 222". What's wrong in my script?

View 2 Replies View Related

Programming :: Redirecting Stdin / Stdout And Stderr For Program Run As Fork()/execl()?

Nov 24, 2010

I'm trying to write a program that will fork a series of FTP sessions. For each session, there should be separate input and output files associated with stdin and stdout/stderr.
I keep reading how I should be able to do that with dup2() in the child process before the execl(), but it's not working for me. Could someone please explain what I've done wrong? The program also has a 30-second sniper alarm for testing and killing of FTPs that go dormant for too long.

The code: (ftpmon.c)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

[code]....

The output:

$ ftpmon
Connected to gila-crstest.gilacorp.com (172.16.20.8).
220 (vsFTPd 2.0.1)
ftp> waitpid(): Interrupted system call

Why am I getting the ftp> prompt? If the dup2() works, shouldn't it be taking input from my script and not my terminal? In stead, it does nothing, and winds up getting killed after 30 seconds. The log file is created, but it's empty after the run.

View 3 Replies View Related

Programming :: Redirecting Stdin / Stdout And Stderr And Finding Files Name And Other Stats?

Aug 8, 2010

I'm working on an application used for backup/archiving. That can be archiving contents on block devices, tapes, as well as regular files. The application stores data in hard packed low redundancy heaps with multiple indexes pointing out uniquely stored, (shared), fractions in the heap.

And the application supports taking and reverting to snapshot of total storage on several computers running different OS, as well as simply taking on archiving of single files. It uses hamming code diversity to defeat the disk rot, instead of using raid arrays which has proven to become pretty much useless when the arrays climb over some terabytes in size. It is intended to be a distributed CMS (content management system) for a diversity of platforms, with focus on secure storage/archiving. i have a unix shell tool that acts like gzip, cat, dd etc in being able to pipe data between applications.

Example:

dd if=/dev/sda bs=1b | gzip -cq > my.sda.raw.gz

the tool can handle different files in a struct array, like:

Code:

enum FilesOpenStatusValue {
FileIsClosed = 0,
FileIsOpen,

[code]....

Is there a better way of getting the file name of the redirected file, (respecting the fact that there may not always exist such a thing as a file name for a redirection pipe).
Should i work with inodes instead, and then take a completely different approach when porting to non-unix platforms? Why isn't there a system call like get_filename(stdin); ?

If you have any input on this, or some questions, then please don't hesitate to post in this thread. To add some offtopic to the thread - Here is a performance tip: When doing data shuffling on streams one should avoid just using some arbitrary record length, (like 512 bytes). Use stat() to get the recommended block size in stat.st_blksize and use copy buffers of that size to get optimal throughput in your programs.

View 4 Replies View Related

Programming :: Libxml2: Removing Output On Stdout/stderr - Element CA Does Not Carry Attribute Maxlength

Jul 26, 2010

I'm using libxml2 to handle/manipulate some XML files. In order to check the consistency of a XML file, I have a DTD and I'm using the xmlValidateDtd method to compute the check.

However, when an error occures during the check (for example an attribute is missing in a XML tag), then libxml2 writes the error on the stdout/stderr. For exemple:

Code:

/home/XML/FreeFour.xml:18: element CA: validity error : Element CA does not carry attribute maxlength

The method return the right result (true or false depending on the check result), but occurring errors are written on the stdout/stderr, and I actually don't want that.

View 4 Replies View Related

Programming :: Redirecting Stdout To File And Terminal And Stderr To File?

Apr 20, 2010

I have a script where I want to redirect stdout to the terminal and also to a log file aswell as redirecting stderr to the same log file but not the terminal.I have the following code which I found on the net which redirects both stderr and stdout to a file and the logfile,

Code: if [ -p $PIPE1 ]
then
rm $PIPE1

[code]...

View 3 Replies View Related

Software :: Qt Creater 4 - C++ & Stderr - Use QDebug() To Print Out Stderr Messages?

Jul 27, 2010

Can I use qDebug() to print out stderr messages? If I just use qDebug() << stderr; I get hex output.

View 1 Replies View Related

Software :: Redirect Stdout To File Produces Blank File

Dec 27, 2008

I cannot redirect output from commands such as iptables, iptables-save, and ifconfig. For example, any of the following DOESN'T work ( as root ):

Code:
iptables > tmp
iptables-save > tmp
ifconfig > tmp
The file tmp is ALWAYS blank, that is, 0 bytes in size. Wackier things DO work, such as:

Code:
echo "`iptables-save`" > tmp
iptables-save | tee tmp
Other commands like:

Code:
ls > tmp
DO work as expected.

Note that this problem happens regardless if I log-in remotely via ssh or locally on the computer in question. I am clueless as to what is causing this. Any ideas?The box is running 2.6.25-14.fc9.i686 and boots to runlevel 3. The modifications I've made to the box since installing the OS are things like compiling/installing latest OpenSSH,OpenSSL,httpd,BerkeleyDB,subversion,zlib etc -- nothing really out of the ordinary I'd say.

View 5 Replies View Related

General :: File Output Redirection - Redirect Stream To Multiple Files?

Dec 7, 2010

I'm working on some scheduled task script files to keep nightly backups of some of our database information in place, and it's a bit annoying when they blow up. I know how to redirect stdout and stderr to a flat file I can view when I come in, and I know that 2>&1 maps them both to the same file (whatever was named in 1). However, I'm running into some cron-time situations where it's easier to have the two streams together, and other cron-time situations where it's easier to have them separated. I can't really tell which is going to happen; is there some way I could create both kinds of output file for my scripts, so that I've got a std_err only file and an interleaved std_out/std_err file?

Note: I've looked at the 'tee' command, but I don't think it will work for what I'm after. 'tee' appears to only work with stdout; I'm trying to work with stderr.

View 5 Replies View Related

General :: How To Execute Multiple Commands When Using Find

Jan 22, 2011

I'm trying to run multiple commands on things I have found, how can I achieve this? find . -exec cmd1; cmd2 does not seem to work; it instead runs cmd2 after cmd1 has been executed on every file.

View 2 Replies View Related

General :: Running Multiple Commands Remotely Via SSH In A Script?

Dec 18, 2009

In a script I am writing I am trying to add logic so that the script can figure out if a remote server uses rpm or dpkg and then run the appropriate command to print a list of installed packages. This works locally, but I need to get it to work through SSH and I have no idea how to do that. The relevant portion of the script is below. It would also be nice to find a way to not need the full path to the executables but I'm not real concerned about that.So anyone know how to make this code work via SSH?

Code:
if [ -x /usr/bin/dpkg ]; then
dpkg --get-selections

[code]...

View 4 Replies View Related

General :: SVN Multiple Commands Single Revision - Add New Folders (with Contents) To The Repository?

Jun 18, 2010

I want to do something like svn add dir1 dir2; svn ci dir1 dir2 but have it be only 1 revision. Is there a way to do this? Is this the correct way to add new folders (with contents) to the repository? We are restructuring the trunk, so I cleared it out and plan on putting these directories with their contents in it.

View 1 Replies View Related

Programming :: Redirect To Multiple Files?

Nov 12, 2010

I feel kind of embarrassed posting here, but this is technically a scripting sub-forum. Here is the problem. I have a folder with various files which include .txt files as well

How can i redirect same content to each of the .txt files in the folder?

I have tried
Code: $ echo "hello" > *.txt
-bash: !": event not found Code: also cat ~/otherdir/test.txt > *.txt
-bash: *.txt: ambiguous redirect Can anyone help me with this?Ok i solved it
Code: #! /bin/bash
for file in *.txt
do
echo "Text that needs to be written" > $file
done

View 2 Replies View Related

Ubuntu Servers :: 301 Redirect Or ServerAlias For Multiple Tld's?

Jun 19, 2011

Our company owns multiple tld's for our corporate domain (e.g. company.com, company.net, etc.). Currently, we operate the main website at [URL]. To have "company.net" et al forward/redirect to "company.com", should we use a 301 redirect or setup a ServerAlias in Apache's virtual host directive (we use name-based virtual hosting on Ubuntu Server). Are there any SEO penalties from one approach vs. the other (e.g. Google thinking you have multiple sites with the same contact + flagging it as spam)?

View 2 Replies View Related

Ubuntu :: Redirect Curl Output To Multiple Files?

Nov 6, 2010

I am using curl as the following

Code:
curl "http://site.com/pages/{1,2,3,4,5}.html" > /home/myuser/allpages.html
i need to save each page in a separate page by the way i have tried this command
Code:
curl "http://site.com/pages/{1,2,3,4,5}.html" > /home/myuser/{1,2,3,4,5}.html
but it displays error
Code:
ambiguous redirect
is there any way to do that

View 5 Replies View Related

Programming :: Redirect The Output To Multiple Files Without Displaying It To The Screen?

Oct 26, 2010

To redirect standard output to multiple files:

Code:

echo Test | tee file1 file2

My problem is that the word "Test" still displays to the screen? I want same effect as:

Code:

echo Test > file1

but with multiple file redirection.

View 3 Replies View Related

General :: Catching Stderr From Dd Over Ssh?

Oct 1, 2010

this might be an interesting one for the bash scripting gurus. I seem to break my teeth on it. The mission:- do a dd over ssh to trasnfer an image to another host- capture the dd PID on the other side- send a USR1 kill signal to it- capture that output on the original host It goes wrong on the last part. This is what I have before that step:dd if=image.gz | gzip -d | ssh host2 "dd of=/dev/vg1/lv1" &PID=`ssh host2 ps aux |grep dd|grep lx05|awk '{ print $2 }'`when I do "ssh host2 kill -USR1 $PIDI get nice outputs to the screen. When I replace the first line with:dd if=image.gz | gzip -d | ssh host2 "dd of=/dev/vg1/l01 2>/tmp/output.txt" &the dd command seemd to die. I suspect a problem with the pipe, since this does work when executing locally on a host without piping.

View 4 Replies View Related

General :: Take A Screen Shot Of A XWindow?

May 17, 2011

I'm using Ubuntu 11.04. In a startup script, I have

Code:
start() {
log_daemon_msg "Starting selenium-server server: "
export DISPLAY=localhost:15.0
/usr/bin/Xvfb :15 -ac -screen 0 1024x768x16 &

From the console, how do I take a screen shot of the display at localhost:15.0 -- my DISPLAY above?

View 3 Replies View Related

General :: Redirecting Output From Stderr?

Dec 1, 2010

I have seen a post where someone was explaining the virtuality of stdout and stderr and that it can be redirected with e.g. 2>file.txt but this apparently is not working for me!
I have a CUPS filter with fprintf(stderr,...)

View 5 Replies View Related

Hardware :: Multiple Barcode Scanners - Can't Seem To Redirect Output From One To A Specific Instance Of My Program

Sep 30, 2010

I have nine barcode scanners, each of whose input I want to send to a separate instantiation of a program I wrote. Each device shows up as /dev/hidraw_ (I'm using Ubuntu 10.4). The problem is that they all act as simple keyboard input, and I can't seem to redirect the output from one to a specific instance of my program. I've tried something like cat /dev/hidraw5 > ./myapp, and that doesn't work. I've tried actually opening the device in my program using open("/dev/hidraw5"), and it returns success, but subsequent reads don't do anything, and the scanner output is just printed to the console.

View 1 Replies View Related

General :: Assign DHCP IP For Client For 5 Interfaces At One Shot?

May 11, 2010

I have a RHEL Machine. All I have is 5 Ethernet cards.I want all of them to be assigned IP through DHCP while I boot my system.

View 4 Replies View Related

General :: Locate And Change All The Search.php Files Permissions To 644 In One Shot?

Apr 18, 2011

I work with this travel company that host sites for different agents. They have ALL the sites in one directory and each site has its own search.php file. How can I locate, and change all the search.php files permissions to 644 in one shot? Is this possible maybe with the find command? I read the man page for this but I am not sure how to write out the command.

View 3 Replies View Related

General :: Log Rotation Of Stdout?

Jun 1, 2011

I have a Linux program which can write information to stdout and stderr.

I have a shell script which redirects that output to a file in /var/log. (Via >> and 2>&1.)

Is there a way to make that log file rotate? (max size, then switch to a different file, keep only a limited number of files)

I've seen a few answers which talk about the logrotate program, which sounds good, but they also seem to be focused on programs which are generating log files internally and handle HUP signals. Is there a way to make this work with a basic output redirection script?

View 3 Replies View Related

Ubuntu :: Multiple Commands At The Terminal?

Jan 21, 2010

I am in the process of coverting some video files to motion jpeg (Wii) files with ffmpeg (great program by the way). I have been successful and so the majority of my work is over. My question is simple (I think) but complex to me so... here it goes. Is there a way on one command line to "batch" convert 8 or 9 files together instead of one by one. I just don't know what to put on the command line. I took one UNIX class a long time ago and the terms pipe and such come to mind... but I forget. Any takers? That was I can write what I want the computer to do in the morning and just come back after work and voila...

View 6 Replies View Related

Software :: Can't Get Head Around The Commands Or How Multiple?

Jan 11, 2011

I'd like to convert some of my backed up ripped DVDs to an .avi with separate subtitle file. I have been looking at MEncoder but I can't get my head around the commands or how multiple .VOB files become a singular .avi file.

View 2 Replies View Related

General :: How To Echo The File To Stdout

Sep 26, 2010

I have a process which logs output to log.txt. If I want to see the process's status in real-time, is there a way to echo that output to stdout instead of opening the log in a text editor and constantly reloading?

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved