[Linux-disciples] write to file from shell script

Stephen R Laniel steve at stevereads.com
Tue Nov 15 22:10:08 EST 2011


The "broken pipe" is expected; Python is kind of dumb like that. (I think you need to set it up to handle SIGPIPE correctly -- i.e., exit gracefully when something on the other end of the pipe closes its stdin.)

I meant, though: what if you replace the "blah blah blah > some_file" bit with "blah blah blah | head" *in the script*?

Also, to test a permissions hypothesis, try just doing "touch whatever_filename" from inside the script and seeing what happens. Let's get down to the very simplest reproduction of the problem.

On Nov 15, 2011, at 10:02 PM, Jamie Forrest wrote:

> On Tue, Nov 15, 2011 at 9:57 PM, Stephen R Laniel <steve at stevereads.com> wrote:
>> What happens if you just dump that output to stdout? Only dump the first few lines, à la
>> 
>> gondor sqldump primary | head
>> 
>> What happens then?
> 
> jforrest$ gondor sqldump primary | head
> Reading configuration... [ok]
> Dumping database... [ok]
> --
> -- PostgreSQL database dump
> --
> 
> SET statement_timeout = 0;
> SET client_encoding = 'UTF8';
> SET standard_conforming_strings = off;
> SET check_function_bodies = false;
> SET client_min_messages = warning;
> Traceback (most recent call last):
>  File "/Users/jforrest/.virtualenvs/django-cnsltme/bin/gondor", line
> 9, in <module>
>    load_entry_point('gondor==1.0', 'console_scripts', 'gondor')()
>  File "/Users/jforrest/.virtualenvs/django-cnsltme/lib/python2.7/site-packages/gondor/__main__.py",
> line 740, in main
>    }[args.command](args, env, config)
>  File "/Users/jforrest/.virtualenvs/django-cnsltme/lib/python2.7/site-packages/gondor/__main__.py",
> line 376, in cmd_sqldump
>    out(d.decompress(chunk))
>  File "/Users/jforrest/.virtualenvs/django-cnsltme/lib/python2.7/site-packages/gondor/utils.py",
> line 30, in out
>    sys.stdout.write(msg)
> IOError: [Errno 32] Broken pipe
> 
> 
>> 
>> On Nov 15, 2011, at 9:28 PM, Jamie Forrest wrote:
>> 
>>> What am I doing wrong? I am trying to write to a file from within a
>>> shell script, but the file doesn't get created. Here's the script:
>>> 
>>> #!/bin/bash
>>> 
>>> NOW=`date +%F`
>>> gondor sqldump primary > $NOW_dump.sql
>>> 
>>> 
>>> (For what it's worth gondor sqldump is a command that dumps a remote
>>> database to sql (primary is the db instance). Generally when I run it
>>> from the cmd line I just run gondor sqldump primary >
>>> whatever_dump.sql and all is fine. I know this command is running ok
>>> because I see its output "Dumping database... [ok]" when I run the
>>> script.)
>>> 
>>> Thanks,
>>> Jamie
>>> _______________________________________________
>>> Linux-disciples mailing list
>>> Linux-disciples at lists.bostoncoop.net
>>> http://lists.bostoncoop.net/mailman/listinfo/linux-disciples
>>> 
>> 
>> --
>> Stephen R. Laniel
>> steve at stevereads.com
>> Cell: +(617) 308-5571
>> http://stevereads.com/
>> PGP key: http://stevereads.com/slaniel.key
>> 
>> _______________________________________________
>> Linux-disciples mailing list
>> Linux-disciples at lists.bostoncoop.net
>> http://lists.bostoncoop.net/mailman/listinfo/linux-disciples
>> 
> 
> 
> 
> -- 
> http://about.me/jamieforrest
> _______________________________________________
> Linux-disciples mailing list
> Linux-disciples at lists.bostoncoop.net
> http://lists.bostoncoop.net/mailman/listinfo/linux-disciples
> 

-- 
Stephen R. Laniel
steve at stevereads.com
Cell: +(617) 308-5571
http://stevereads.com/
PGP key: http://stevereads.com/slaniel.key



More information about the Linux-disciples mailing list