Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

How to save the output of the script in different directory in Bash?

user-image
Question added by Mudassir Mubin Baig , Network Engineer , Saima Packaging Pvt. Ltd.
Date Posted: 2016/03/07
Carlos Perez
by Carlos Perez , RAN Engineer , Grupo Poas

both outputs; on screen and to file.log: 

' command '2>&1 | tee -a file.log

ASHISH VERMA
by ASHISH VERMA , Software Engineer , Ragon Systems

 $HOME/bin/shell_script.sh >/home/usr/test.log 2>&1

Khaja Ehteshamuddin  Ahmed
by Khaja Ehteshamuddin Ahmed , IT Analyst , Tata Consultancy Services

We can run the script using and redirect the output to a file rather than to the screen.

Ex: ./script.sh > /home/dir1/file1 We are executing the script and saving the output to a file called file1

benyahia oussama
by benyahia oussama , Network and Security Administrator , ELIT

DIR="NewDirectory" mkdir -p $DIR echo "Testing">>"$DIR/file.txt"

Anil Mathew Kadakethu
by Anil Mathew Kadakethu , Technical Support Manager , M H Alshaya

yourcommand 1>> path/log_file 2>&1this redirect stdout and sterr to log_file

 

NIVETHA SENTHILKUMAR
by NIVETHA SENTHILKUMAR , Software Engineer , infosys

The oup\\tput can be save in a new directory using redirecting symbol >>

First capture the output of the script using a backtick and then pipe it into an echo command which writes into a specified file in a specified directory.

$ ./yourscript.sh > output.txt$ /path/to/your/script.sh > output.txt

do something like this ./script.sh > /tmp/output.log 2>&1

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.