Skip to main content

Thread: bash script output redirect


hello!

have single "backup.sh" script containing multiple rsync commands:

code:
#!/bin/bash    echo $(date)    #data  rsync -avrp ~/data/ /backup/data/    #media  rsync -avrp ~/media/ /backup/media/    #email  rsync -avrp ~/email/ /backup/email/    read    exit
what trying do, specifically, place command inside script, itself, direct (sequential) output of 3 rsync commands (as echo $(date)) both terminal , (date-stamped) log file - akin to:
code:
tee backup_log_`date +"%m%d%y_%h%m"`
...which (when incorporated - in various ways - script - without "|") directs output terminal but generates empty date-stamped log file.

or

code:
> backup_log_`date +"%m%d%y_%h%m"`
...which (when incorporated - in various ways - script) closes terminal , generates empty date-stamped log file.

have toyed adding "> backup_log" (and ">> backup_log") or "tee backup_log" etc after each command - however, struck me inefficient.

have constructed line...
code:
$ ./backup.sh | tee backup_log_`date +"%m%d%y_%h%m"`
...in terminal - , within desktop launcher (though not date stamp work launcher, using sh -c), yield trying yield (i.e. output both terminal , (dated) log). however, i'd rather have functionality incorporated script, - if feasible....

seems need kind of "collect / consolidate / redirect output of multiple commands within bash script" insight! perhaps there bash "function" gather commands , collect output (sort of javascript-esque)?

guidance!

you are, in fact, correct. there way "collect / consolidate / redirect output of multiple commands within bash script".

putting () around bash commands consolidate of output. can test out on terminal, if try running
code:
(date; echo hello, world) > output
you see both output of date , "hello, world" in file output.

can put "(" on first line of shell script , ") > [your output stuff]", , should want.

hope helps, , response isn't late useful!


Forum The Ubuntu Forum Community Ubuntu Official Flavours Support General Help [SOLVED] bash script output redirect


Ubuntu

Comments

Popular posts from this blog

How to change text Component easybook reloaded *newbee* - Joomla! Forum - community, help and support

After Effect warning: A problem occurred when processing OpenGL commands

Preconditions Failed. - Joomla! Forum - community, help and support