News for hackers. Stuff that matters.
Re:How To Log Bash History to Syslog by atesti on Friday November 11, 2011 @11:01AM (#3225004)
What does history -a do? Seems to write the history to disc and not produce something to pipe into logger. How does this work?
Re:How To Log Bash History to Syslog by despite2 on Friday November 11, 2011 @11:29AM (#3225097)
With bash putting a command in <() uses the output of the command as though it were a file. I use it to diff the output of two commands: diff <(command 1) <(command 2)

I've never used it, but I assume >() uses a command as though it were a writable file. So instead of history -a file writing to file, he does history -a >(logger) to write to the logger command. Seems pretty clever to me.

Re:How To Log Bash History to Syslog by zooz on Friday November 11, 2011 @11:36AM (#3225120)
Yup, that's what it does. Shortly speaking <() or >() in bash that creates a temporary pipe.
Re:How To Log Bash History to Syslog by sciurus on Friday November 11, 2011 @03:33PM (#3226045)
It's called process substitution. In this case it runs the logger command, connects its input to a file in /dev/fd, and places the name of that file in the argument list of history. I've included a small demonstration below. This is useful since the history command won't write to standard out so you can't use a normal pipe. It's more common to see process substitution used to gather output from multiple commands, see http://www.linuxjournal.com/content/shell-process-redirectio...

    $ cat writer.sh 
    #!/bin/bash
    if [[ "$#" == 1 ]]; then
        echo "Wrote to file named $1" > "$1"
    else
        echo "Wrote to stdout"
    fi

    $ ./writer.sh 
    Wrote to stdout

    $ ./writer.sh | cat
    Wrote to stdout

    $ ./writer.sh >(cat)
    Wrote to file named /dev/fd/63
Re:How To Log Bash History to Syslog by zooz on Friday November 11, 2011 @11:24AM (#3225075)
It appends the "new" history lines to a $HISTFILE by default, unless other file is specified.
Re:How To Log Bash History to Syslog by atesti on Friday November 11, 2011 @02:23PM (#3225796)
Thanks, that's what I was missing: -a can have a file. Cool stuff and thanks to all for explaining it. http://unixhelp.ed.ac.uk/CGI/man-cgi?history does not mention the command line argument, http://linux.die.net/man/1/bash does.
Re:How To Log Bash History to Syslog by zooz on Friday November 11, 2011 @02:42PM (#3225859)
You're welcome, it took me a bit of time to come up with this idea, of course, it's not perfect, but does the job pretty well.