Reputation: 5941
In a shell script i have
LOG=/my.log
exec 1>>$LOG
exec 2>&1
which redirects the output in shell script. Now the problem is in the following
LOG=/etc/security/aixpert/log/aixpert.log
exec 1>>$LOG
exec 2>&1
#some codes
print "I want this on cmd output not in log"
#I want rest of the output redirected to log as usual
How can i do this??
Upvotes: 2
Views: 1539
Reputation: 363817
# save stdout as fd 3
exec 3>&1
exec 1>>$LOG
exec 2>&1
echo foo >&3 # output to old stdout
echo bar # output to logfile
Upvotes: 2
Reputation: 140497
The key is to clone stdout
going to the console to an arbitrary fd (I chose 3) before your redirect it to your log. Whenever you want to send output to the console you just redirect fd 1 back to fd 3 with >&3
for that one command
LOG=/etc/security/aixpert/log/aixpert.log
exec 3>&1 >>"$LOG" 2>&1
#some codes
echo "I want this on cmd output not in log" >&3
#I want rest of the output redirected to log as usual
Upvotes: 4