I've written a short bash script to update some twitter_ebooks bots. The commands involved generate a lot of output and I want to redirect it to a file with the day's date. I tried using the top aswer to this question on ask ubuntu however the vast majority of the output still goes to the terminal.
My bash script:
#!/bin/bash
arc() { ## $1 is account name $2 is log file
ebooks archive $1 corpus/$1.json >> "$2"
ebooks consume corpus/$1.json >> "$2"
}
accounts=(some twitter names)
echo "moving to ~/twitter/snare_ebooks"
cd ~/twitter/snare_ebooks
date_var=$(date -d @$(date +%s) +"%m_%d_%Y")
logfile=~/ebooks_archive_logs/$date_var.log
touch "${logfile}"
echo "model update log for $date_var" >> "${logfile}"
echo "archiving and consuming the corpus"
for accountName in ${accounts[*]}
do
arc $accountName "${logfile}"
done
echo "git adding"
git add --all . >> "${logfile}"
echo "git committing"
git commit -m "model update" >> "${logfile}"
echo "pushing to heroku"
git push heroku master >> "${logfile}"
The log file that is created only contains:
model update log for 07_28_2015
[master 2eb0961] model update
4 files changed, 134 insertions(+), 134 deletions(-)
Can anyone explain why this isn't working as expected? Also what needs to be done in order for it to work as expected?
-d @$(date +%s)is unnecessary; you're just tellingdateto use the current time (which is the default).arc "$accountname" >> "$logfile"is better than doing the redirection in the function twice. Similarly doing the redirection once on the entire contents of the script would be even better.&>>and it worked like a charm! If you write an answer I'd love to mark it as the correct answer