将屏幕输出重定向到文件

时间:2020-10-07 16:07:12

标签: bash file output screen scp

我正在尝试将屏幕输出重定向到日志文件,但似乎无法正确执行,请参见下面的代码:

DT=$(date +%Y-%m-%d-%H-%m-%s)
echo $DT > log_copy_$DT.txt

cat dirfiles.txt | while read f ; do
dest=/mydir
scp "${f}" $dest >> log_copy_$DT.txt 2>&1
done

我得到的只是带有日期的文件,而不是带有屏幕结果的文件(我需要查看文件是否正确复制)。

因此,基本上,我将scp命令的结果附加到日志中并执行2>&1,以便将标准输出屏幕写入文件,但似乎不起作用。

我需要在crontab上运行它,所以我不确定设置后屏幕内容是否还会进入日志。

1 个答案:

答案 0 :(得分:0)

好吧,在调查之后,scp似乎无法真正将标准屏幕输出写入文件,因为它显示了进度百分比,所以它有点取消了标准,所以我最终这样做了:

karma.conf.js
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
const { join } = require('path');
module.exports = function (config) {
  const puppeteer = require('puppeteer');
  process.env.CHROME_BIN = puppeteer.executablePath();
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage'),
      require('karma-junit-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular-devkit/build-angular/plugins/karma')
    ],
    client: {
      jasmine: {
        random: false,
      },
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    files: [
      // Include a Material theme in the test suite.
      { pattern: './node_modules/@angular/material/prebuilt-themes/indigo-pink.css', included: true, watched: true }
    ],
    coverageIstanbulReporter: {
      dir: 'coverage',
      reports: ['lcovonly', 'text', 'cobertura'],
      fixWebpackSourcePaths: true
    },
    junitReporter: {
      outputDir: join(__dirname, 'testresults'),
      outputFile: 'unit-test-result.xml',
      useBrowserName: false
    },
    reporters: ['progress', 'kjhtml', 'junit'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    customLaunchers: {
      ChromeHeadlessCI: {
        base: 'ChromeHeadless',
        flags: [
          '--no-sandbox',
          '--disable-web-security',
          '--disable-gpu']
      }
    },
    singleRun: false,
    captureTimeout: 190000, // default: 60000
    browserDisconnectTimeout: 190000,
    retryLimit: 4,
    browserDisconnectTolerance: 6,
    browserNoActivityTimeout: 190000,// default: 10000
  });
};

基本上,它可以复制文件,然后写一条消息,说没问题。