Thread: bash script output redirect
hello!
have single "backup.sh" script containing multiple rsync commands:
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:#!/bin/bash echo $(date) #data rsync -avrp ~/data/ /backup/data/ #media rsync -avrp ~/media/ /backup/media/ #email rsync -avrp ~/email/ /backup/email/ read exit
...which (when incorporated - in various ways - script - without "|") directs output terminal but generates empty date-stamped log file.code:tee backup_log_`date +"%m%d%y_%h%m"`
or
...which (when incorporated - in various ways - script) closes terminal , generates empty date-stamped log file.code:> backup_log_`date +"%m%d%y_%h%m"`
have toyed adding "> backup_log" (and ">> backup_log") or "tee backup_log" etc after each command - however, struck me inefficient.
have constructed line...
...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....code:$ ./backup.sh | tee backup_log_`date +"%m%d%y_%h%m"`
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
you see both output of date , "hello, world" in file output.code:(date; echo hello, world) > 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
Post a Comment