Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

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

user-image
Question ajoutée par Mudassir Mubin Baig , Network Engineer , Saima Packaging Pvt. Ltd.
Date de publication: 2016/03/07
Carlos Perez
par Carlos Perez , RAN Engineer , Grupo Poas

both outputs; on screen and to file.log: 

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

ASHISH VERMA
par ASHISH VERMA , Software Engineer , Ragon Systems

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

Khaja Ehteshamuddin  Ahmed
par 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
par benyahia oussama , Network and Security Administrator , ELIT

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

Anil Mathew Kadakethu
par 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
par 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

Avez-vous besoin d'aide pour créer un CV ayant les mots-clés recherchés par les employeurs?