简体   繁体   English

在单个文件夹中运行3个脚本

[英]Run 3 scripts in single folder

I have a script that will run 3 scripts, these 3 scripts i need to put it into a folder called date and time which will take from the system. 我有一个脚本,它将运行3个脚本,我需要将这3个脚本放入名为date and time的文件夹中,该文件夹将从系统中取出。

For example 例如

  1. i have a 3 scripts called A.sh, B.sh, C.sh these three scripts are running from a single script. 我有一个名为A.sh,B.sh,C.sh的3个脚本,这三个脚本是从单个脚本运行的。
  2. each script has a different output. 每个脚本都有不同的输出。
  3. These three outputs should be in a single directory called date_and_time 这三个输出应该在一个名为date_and_time的目录中
  4. I will give you a small picture how the out put should be http://photouploads.com/images/example.png 我会给您一个小图片,输出应该如何http://photouploads.com/images/example.png

Can any one suggest me how to solve this problem 谁能建议我如何解决这个问题

You can use smth like this: (contents of your running script, say run3.sh ) 您可以这样使用smth :(正在运行的脚本的内容,例如run3.sh

#!/bin/bash
A.sh > date_and_time/A.output &
B.sh > date_and_time/B.output &
C.sh > date_and_time/C.output &

you may also use a sub shell like this: 您还可以使用以下子外壳:

#!/bin/bash
DIRNAME=$(date +"%Y%m%d-%H%M%S")
( $DIRNAME/A.sh ; $DIRNAME/B.sh ; $DIRNAME/C.sh ) > $DIRNAME/Text.txt

If what you want is to have timestamped output directories, this might be a good starting point: 如果您想要的是带有时间戳的输出目录,那么这可能是一个很好的起点:

#!/bin/sh

TIMESTAMP=`date +"%Y-%m-%d-%H:%M:%S"`

OUTPUT="$TIMESTAMP.d"

mkdir -p "$OUTPUT"

A.sh > "$OUTPUT/A.out"
B.sh > "$OUTPUT/B.out"
C.sh > "$OUTPUT/C.out"

echo "Lorem ipsum dolor sit amet..." > "$OUTPUT"/Text.txt

# Let our users know where to find the output...
echo "Output directory: $OUTPUT"

Basically, this script uses the date command to get the current date and time in a more standardized format and then creates an output directory with the same name. 基本上,此脚本使用date命令以更标准化的格式获取当前日期和时间,然后创建具有相同名称的输出目录。

Caveat: If you run this script twice within the same computer clock second, the output of the second run will overwrite the first one. 注意:如果您在同一计算机时钟秒内两次运行此脚本,则第二次运行的输出将覆盖第一个。 I'll leave handling this particular corner case as an exercise for the reader... 我将处理这个特殊的案例作为练习供读者阅读...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM