Redirect output from a shell script to a file

2019-05-25 09:19发布

问题:

I'm busy writing up a Capistrano deployment script for one of our applications. One of the steps installs RVM using the following command:

run "cat ~/rvm-installer.sh | bash -s stable --ruby"

However, I feel the output is too verbose, and I rather want to dump it into a .log file. Is it possible to redirect the output for the entire rvm-installer.sh script elsewhere?

回答1:

Like this:

run "cat ~/rvm-installer.sh | bash -s stable --ruby >out.log"

or, if you want to redirect standard error stream of the process as well:

run "cat ~/rvm-installer.sh | bash -s stable --ruby >out.log 2>err.log"

you can also redirect everything to the same file:

run "cat ~/rvm-installer.sh | bash -s stable --ruby >out.log 2>&1"