【问题标题】:Trying to make a loop试图做一个循环
【发布时间】:2013-11-04 05:53:41
【问题描述】:

我正在尝试制作循环脚本,但似乎无法正确执行。到目前为止,这是我的脚本 - 我可以让它与 2 个 if 语句一起工作,但就像我说的那样,我试图让它变成一个循环。我对脚本非常陌生,希望有任何建议。谢谢

#!/bin/bash
#source "/node/procTestData/test_directory"
session1="/node/procTestData/test_directory/path_to.proc"     
session2="/node/procTestData/test_directory/path_to.proc2"

file1="/node/procTestData/test_directory/000scratch/path_to.log"
file2="/node/procTestData/test_directory/path_to.log"


dir=$PWD
echo "this is $dir" 

rundir1="/node/procTestData/test_directory/000scratch/single.app/work*"
rundir2="/node/procTestData/test_directory/000scratch/Test.app/work*"

/d/sw/dugproc/20130927/_appCmdLine "$session1"
wait
/d/sw/dugproc/20130927/_appCmdLine "$session2"

wait

echo "session is"
echo $session1
echo $session2

wait

echo "rundir is"
echo $rundir1
cd $rundir1
./run_harness.sh

wait

echo "rundir is"
echo $rundir1
cd $rundir1
./run_harness.sh

wait

echo $rundir2
cd $rundir2
./run_harness.sh

wait

echo "this is $dir"
cd $dir
echo "this is file1"
echo $file1
echo $file2

wait
#       for par in $file1; do
#       if [ -e $par ]; then 
#       echo "this is par"
#       echo "$par" 
#       fi 
#       for par2 in $file2; do
#       if [ -e $par2 ]; then
#       echo "this is par2"
#       echo "$par2"
#       fi
#       done

    for $par in ($file1 , $file2); do
    if [ -e $par ]; then
    echo "this is par"
    echo "$par"
    elif [ -e $par ]
    echo "this is par2"
    echo "$par"
    fi
#       done
exitmessage=$(grep "volume created successfully" $par $par2)
error1=$(grep "error" $par $par2)
error2=$(grep "ERROR" $par $par2)
error3=$(grep "SEVERE" $par $par2)
error4=$(grep "severe" $par $par2)
error5=$(grep "Error" $par $par2)
error6=$(grep "Severe" $par $par2)
error7=$(grep "WARNING" $par $par2)
error8=$(grep "Warning" $par $par2)
error9=$(grep "warning" $par $par2)

echo $error1 
echo $error2
echo $error3
echo $error4
echo $error5
echo $error6
echo $error7
echo $error8
echo $error9
echo $exitmessage 
echo "finished"
done
2>&1 > darraghLogFile.log || exit 100

【问题讨论】:

  • 你到底想要什么??你想让这个脚本在一个循环中连续运行吗??
  • wait 没有做任何有用的事情,因为脚本没有异步执行任何命令。

标签: linux bash loops if-statement


【解决方案1】:

实际上完全不清楚您要做什么,但也许您正在寻找类似的东西:

#!/bin/bash
source=/node/procTestData/test_directory
session1=$source/path_to.proc  
session2=$source/path_to.proc2   
rundir1=$source/000scratch/single.app/
rundir2=$source/000scratch/Test.app/

while read session rundir; do
    /d/sw/dugproc/20130927/_appCmdLine "$session"    
    cd $rundir
    ./run_harness.sh
done << EOF
$session1 $rundir1
$session2 $rundir2
EOF

【讨论】:

    猜你喜欢
    • 2021-09-26
    • 1970-01-01
    • 2019-03-08
    • 2011-11-28
    • 1970-01-01
    • 2020-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多