Solved Shell Scripting Output to File and Screen

Hello all,
I wrote a script to direct all output to a log file, but I'd like to echo certain things during the process of the script to screen output if I can. I haven't been able to find anything related to this searching online, and the man page for sh is cryptic for me (as of now).
Sample of script:
Code:
#!/bin/sh
exec > /path/to/logfile.log
exec 2>&1
rsync command
I'd like to see about printing to screen echo "Sync process started" at the start of the rsync command in the script, and something about it completing after the command executes, but have that print to screen, rather than the log file.
I appreciate all responses in advance!
 
I am not very good at scripting but something like this should work:

Code:
#!/bin/sh
exec > /path/to/logfile.log
exec 2>&1
echo "Sync process started"
rsync command
echo "Sync process done"
 
You may want to have a look at the tee(1) command.

rsync something remote:something | tee my.log

The tee(1) command basically splits your output two ways, once to the screen and once to a file.

Code:
echo "Starting" | tee -a /path/to/logfile.log
rsync <command> >> /path/to/logfile.log 2>&1
echo "Done" | tee -a /path/to/logfile.log
 
lebarondemerde -I have tried the echo command like that in the script before, and all that does is print that output to the log file.
SirDice I thank you for the input, but I'd like something that echoes to the screen, as in a progress/status update of the script, rather than redirect to a file.
 
Save the original stdout and use it later:
Code:
#!/bin/sh
exec 3>&1
exec > logfile.log     
exec 2>&1
echo "Sync process started" >&3
rsync command
echo "Sync process stopped" >&3
 
Back
Top