简体   繁体   中英

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.

For example

  1. i have a 3 scripts called A.sh, B.sh, C.sh these three scripts are running from a single script.
  2. each script has a different output.
  3. These three outputs should be in a single directory called date_and_time
  4. I will give you a small picture how the out put should be 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 )

#!/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.

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...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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