|
藍森林 http://www.lslnet.com 2006年6月26日 11:18
請教變量在for中的意思
[code][sam@Linux_chenwy sam]$ cat audit_run
#!/bin/sh
APPS="/apps/accts /apps/claims /apps/stock /apps/serv"
SCRIPTS="audit.check report.run cleanup"
LOGFILE=audit.log
MY_DATE=`date +%H:%M" on "%d/%m/%Y`
for loop in $APPS
do
for loop2 in $SCRIPTS
do
echo "system $loop now running $loop2 at $MY_DATE" |tee -a $LOGFILE
$loop $loops2 &
done
done[/code]
[code]$loop $loops2 &[/code]
這個在這段腳本裡是什麼意思呢??????
如果去掉這個我就能正常運行,這是抄來的,為什麼多那兩個? |
請教變量在for中的意思
應該是${loop}$loop2 &吧
前面是組合路徑pwd和文件名basename,&是表示後台運行 |
請教變量在for中的意思
在第一次循環是這樣的
/apps/accts audit.check & |
請教變量在for中的意思
第一種: 有$loop $loops2 &
[code][sam@chenwy sam]$ cat audit_rum
#!/bin/sh
APPS="/usr/sam/accts /usr/sam/claims /usr/sam/serv"
SCRIPTS="audit.check report.run cleanup"
LOGFILE=audit.log
MY_DATE=`date +%H:%M" on "%d/%m/%Y`
for loop in $APPS
do
for loop2 in $SCRIPTS
do
echo "system $loop now running $loop2 at $MY_DATE" |tee -a $LOGFILE
$loop $loops2 &
done
done[/code]
[code][sam@chenwy sam]$ ./audit_rum
system /usr/sam/accts now running audit.check at 19:17 on 13/12/2004
system /usr/sam/accts now running report.run at 19:17 on 13/12/2004
system /usr/sam/accts now running cleanup at 19:17 on 13/12/2004
system /usr/sam/claims now running audit.check at 19:17 on 13/12/2004
system /usr/sam/claims now running report.run at 19:17 on 13/12/2004
system /usr/sam/claims now running cleanup at 19:17 on 13/12/2004
system /usr/sam/serv now running audit.check at 19:17 on 13/12/2004
system /usr/sam/serv now running report.run at 19:17 on 13/12/2004
system /usr/sam/serv now running cleanup at 19:17 on 13/12/2004[/code]
[code][sam@chenwy sam]$ cat audit.log
system /usr/sam/accts now running audit.check at 19:17 on 13/12/2004
system /usr/sam/accts now running report.run at 19:17 on 13/12/2004
system /usr/sam/accts now running cleanup at 19:17 on 13/12/2004
system /usr/sam/claims now running audit.check at 19:17 on 13/12/2004
system /usr/sam/claims now running report.run at 19:17 on 13/12/2004
system /usr/sam/claims now running cleanup at 19:17 on 13/12/2004
system /usr/sam/serv now running audit.check at 19:17 on 13/12/2004
system /usr/sam/serv now running report.run at 19:17 on 13/12/2004
system /usr/sam/serv now running cleanup at 19:17 on 13/12/2004[/code]
第二種: 無$loop $loops2 &
[code][sam@chenwy sam]$ cat audit_rum
#!/bin/sh
APPS="/usr/sam/accts /usr/sam/claims /usr/sam/serv"
SCRIPTS="audit.check report.run cleanup"
LOGFILE=audit.log
MY_DATE=`date +%H:%M" on "%d/%m/%Y`
for loop in $APPS
do
for loop2 in $SCRIPTS
do
echo "system $loop now running $loop2 at $MY_DATE" |tee -a $LOGFILE
# $loop $loops2 &
done
done[/code]
[code][sam@chenwy sam]$ ./audit_rum
system /usr/sam/accts now running audit.check at 19:18 on 13/12/2004
system /usr/sam/accts now running report.run at 19:18 on 13/12/2004
system /usr/sam/accts now running cleanup at 19:18 on 13/12/2004
system /usr/sam/claims now running audit.check at 19:18 on 13/12/2004
system /usr/sam/claims now running report.run at 19:18 on 13/12/2004
system /usr/sam/claims now running cleanup at 19:18 on 13/12/2004
system /usr/sam/serv now running audit.check at 19:18 on 13/12/2004
system /usr/sam/serv now running report.run at 19:18 on 13/12/2004
system /usr/sam/serv now running cleanup at 19:18 on 13/12/2004[/code]
[code][sam@chenwy sam]$ cat audit.log
system /usr/sam/accts now running audit.check at 19:18 on 13/12/2004
system /usr/sam/accts now running report.run at 19:18 on 13/12/2004
system /usr/sam/accts now running cleanup at 19:18 on 13/12/2004
system /usr/sam/claims now running audit.check at 19:18 on 13/12/2004
system /usr/sam/claims now running report.run at 19:18 on 13/12/2004
system /usr/sam/claims now running cleanup at 19:18 on 13/12/2004
system /usr/sam/serv now running audit.check at 19:18 on 13/12/2004
system /usr/sam/serv now running report.run at 19:18 on 13/12/2004
system /usr/sam/serv now running cleanup at 19:18 on 13/12/2004[/code]
沒啥區別啊好像 |
請教變量在for中的意思
你的日誌是命令行直接打印的,又不是[code]$loop $loops2 & [/code]返回的,它執不執行都不會對日誌產生影響啊,我還保留我第一次回復的意見,你嘗試一下看看能不能達到你想要實現的動作。我認為這個腳本想實現的功能就是遍歷執行每個目錄下的文件(當然這幾個目錄和文件都已經固定)。 |
請教變量在for中的意思
-->
好像它們都是程序, 是吧?
APPS="/apps/accts /apps/claims /apps/stock /apps/serv「 |
請教變量在for中的意思
應該是以空格為間隔 循環4次
因為shell默認空格為分隔符 APPS="/apps/accts /apps/claims /apps/stock /apps/serv「 被分四段 |
請教變量在for中的意思
嘿,其它的都知道,就是這個
$loop $loops2 &
好像是多餘的 |
請教變量在for中的意思
不是多餘的吧,要是不執行,那打出的日誌豈不是和現實不符的? |
請教變量在for中的意思
[quote="寂寞烈火"]在第一次循環是這樣的
[b]/apps/accts audit.check &[/[/b]quote]
$loop $loops2 &
的作用啊,整個程序的核心啊。 |
請教變量在for中的意思
-->
當然不是多餘的,最重要的就是他,這行命令變成這樣就好讀了
eval $loop $loops2 & |
請教變量在for中的意思
被迷惑了 :oops: :oops: :oops:
請問如何把&這行的執行結果包括正解或錯誤的都寫入日誌??? |
請教變量在for中的意思
-->
eval $loop $loops2 2>&1|tee -a /var/log/mylog & |
請教變量在for中的意思
-->
[code]eval $loop $loops2 >>/var/log/mylog 2>&1 &[/code]
謝謝,忘了>和>>的區別了,謝謝各位。。。。。 :oops: :oops: :oops: |
請教變量在for中的意思
[code]#!/bin/sh
SAVEDIFS=$IFS
IFS=:
HOLD_FILE=hold_file
NAME_MATCH="chenwy"
INPUT_FILE=passwd
>$HOLD_FILE
while read NAME DEPT ID AA BB CC DD
do
echo $NAME $DEPT $ID $AA $BB $CC $DD >>$HOLD_FILE
if [ "$NAME" = "$NAME_MATCH" ];then
echo "all $NAME_MATCH in $HOLD_FILE"
exit 0
fi
done < $INPUT_FILE
IFS=$SAVEDIFS[/code]
>$HOLD_FILE
這個是新建一個文件吧???不敢確定 |
請教變量在for中的意思
不存在此文件時是創建文件,存在此文件時是清空文件內容! |
請教變量在for中的意思
| |
|