For the following script
install.csh:
#!/bin/csh -f tar -zxf Python-3.1.1.tgz cd Python-3.1.1 ./configure make make install cd .. rm -rf Python-3.1.1
Intended use:
./install.csh |& tee install.log
How can I change the script so that I still get a install.log and the output on console without asking the user to do the redirecting?
Some simple solutions:
Solution 1:
tee every line you want to log independently, make use of -a
switch of tee to append
#!/bin/csh -f
tar -zxf Python-3.1.1.tgz |& tee -a install.log
cd Python-3.1.1 |& tee -a install.log
./configure |& tee -a install.log
make |& tee -a install.log
make install |& tee -a install.log
cd .. |& tee -a install.log
rm -rf Python-3.1.1 |& tee -a install.log
Solution 2: Add a second script. For example, rename current install.csh to install_commands, then add a new install.csh script:
#!/bin/csh -f
/bin/csh install_commands |& tee install.log