-1
我將一堆相同的腳本(generate_records.php
)啓動到屏幕中。我正在這樣做,以便輕鬆並行化流程。我想使用類似&> log_$i
(StdOut和StdErr)將每個PHP進程的輸出寫入日誌文件。將`screen` CLI命令啓動的子進程的輸出寫入日誌文件?
我的shell腳本很弱,我無法獲得正確的語法。我不斷收到屏幕的輸出,這是空的。
〔實施例:launch_processes_in_screens.sh
max_record_id=300000000
# number of parallel processors to run
total_processors=10
# max staging companies per processor
((num_records_per_processor = $max_record_id/$total_processors))
i=0
while [ $i -lt $total_processors ]
do
((starting_id = $i * $num_records_per_processor + 1))
((ending_id = $starting_id + $num_records_per_processor - 1))
printf "\n - Starting processor #%s starting at ID:%s and ending at ID: %s" "$i" "$starting_id" "$ending_id"
screen -d -m -S "process_$i" php generate_records.php "$starting_id" "$num_records_per_processor" "FALSE"
((i++))
done
你爲什麼使用'screen'?爲什麼不使用正常的shell I/O重定向將輸出發送到文件? ('php generate_records.php'$ starting_id「」$ num_records_per_processor「」FALSE「> log-for- $ start_id.txt 2>&1&') – larsks
我使用'screen'並行啓動一堆相同的腳本。我認爲你的命令可以正常工作,但我無法在'screen'命令的上下文中使用它。這是一個'screen'命令或sh語法問題,我正在努力與我想。 –