debugging - bash storing the output of set -x to log file -


I have a simple download script and I use set -x which works great Does; I can see each step and I can identify errors in the script or in the download:

  #! / Bin / bash set -x #short_date = $ (/ bin / date +% M% d% y) short_date = $ (/ bin / date -d "8 days ago" +% m% d% y) # long_date = $ (/ Bin / date +% Y% m% d) long_date = $ (/ bin / date -d "8 days ago '+% Y% m% d) SCP -v-p 1332 I / home / casper /. Ssh / id_rsa_BANK friendly @ 192.168.1.10: / home / friendly / transfer / out / EXCHANGE_ $ short_date.csv /local/casper3/dailymetrics/BANK_$long_date.csv  

Is there a way to automate that I can save the set -x output to the log file? Probably a log file - or a different log file for every day. I do not know What's the best thing to do?

The sample below is set -x output from the script

  ++ / bin / date +% m% D% y + short_date = 102814 ++ / bin / date +% y% m% d + tall_data = 20141028 + scp -v -p 1332 I /home/casper/.ssh/id_rsa_BANK friendly @ 192.168.1.10: / home / Friendly / transfer / out / EXCHANGE_102814.csv /local/casper3/dailymetrics/BANK_20141028.csv Execute: program / usr / bin / ssh host 192.168.1.10, user-friendly order SCP -v -f / home / friendly / transfer / Out / EXCHANGE_102814.csv OpenSSH_5.3p1 OpenSSL 1.0.0-FIPS 29 March 2010 debug1: Reading Configuration Data /home/casper/.ssh/ Config debug1: Reading configuration data / etc / ssh / ssh_config debug1: * debug1 Applying Options: Connecting to 192.168.1.10 [192.168.1.10] Port 7777. Debug 1: Installation of Connection  

After "Text" Itemprop = "text">

Assume the bash 4, BASH_XTRACEFD can be set to override the file descriptor (by default 2, stderr) in which set -x The output is written:

  short_date = $ (/ bin / date +% m% d% y) Executive {BASH_XTRACEFD} & gt; & Gt; Setting "$ SHORT_DATE" to log -x  

If 4.1 or new is running instead of Bash 4.0, you have allocated the file descriptor rather than the BASH_XTRACEFD, which means that you have to manually Will need to be appointed; In the example below, I am picking the file descriptor 100:

  short_date = $ (/ bin / date +% m% d% y) exec 100 & gt; & Gt; "$ Short_date" .log BASH_XTRACEFD = 100 set -x  

For the old release, it is your own choice, all of stderr has to be redirected, not just from the xtrace stream:

  SHORT_DATE = $ (/ bin / date +% m% d% y) exec 2 & gt; & Gt; "$ Short_date.log" set -x  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -