2010-10-28 103 views
2

bash腳本幫助,需要bash腳本,需要家庭作業

+0

儘管這似乎是一個很好的問題,恐怕我還沒有完全接受這個挑戰。您可能會將其重新發布/遷移到其他主板之一 - 這裏有Server Fault和Unix/Linux,它們都應該能夠提供更快更好的答案。或者當我點擊添加評論時,有人會發佈一個很好的答案,我會看起來甚至是愚蠢的。 – 2010-10-28 17:52:28

+0

它似乎不能正常工作......發生了什麼?該腳本將處理三個用戶作爲參數,然後所有用戶都在'/ etc/passwd' – philant 2010-10-28 17:57:04

+0

這看起來很有趣,希望我能稍微回來一些幫助 – Orbit 2010-10-28 17:57:13

回答

1

幫助而不是像這樣在輸入指定$ 1 $ 2 $ 3循環:

for user ; do 

然後,你需要將所有的$ 1 to $ user

+3

你幾乎從不想要'$ *'。改爲使用'「$ @」'。或者只是刪除序列完全迭代; 'for'的默認值是'$ @'。 – 2010-10-28 18:06:48

+0

我沒有意識到變量之間的差異。我會更新以反映這一點。 – 2010-10-28 18:27:49

+0

你的意思是應該是這樣的: – trs 2010-10-28 18:39:32

5

代碼從最初的帖子看來似乎已經消失...捲起了一個例子。

#!/bin/bash 

function mod { 
    if [ -d "/Users/$1/share" ]; then 
     echo "permissions changes for $1" 
     #chmod 750 /Users/$1/share 
     #find /Users/$1/share -type f -exec chmod 744 {} \; 
     #find /Users/$1/share -type d -exec chmod 750 {} \; 
     #find /Users/$1/ -type f -exec chmod 600 {} \; 
     #find /Users/$1/ -type d -exec chmod 700 {} \; 
    fi 
} 

function clean { 
    IFS=':' read -ra pw <<< "$1" 
    local c=0 
    local n="" 
    local t=500 
    for i in "${pw[@]}"; do 
     if [ $c == 0 ]; then 
      n="$i" 
     fi 
     if [ $c == 2 ]; then 
      if [ "$i" -gt "$t" ]; then 
       mod $n 
      fi 
     fi 
     c=$[$c+1] 
    done 
} 

function report { 
    export user=$(whoami) 
    ls -la "/Users/$user" > report.txt 
} 

if [ -z $1 ]; then" 
    while read line; do 
     if [ "${line:0:1}" != "#" ]; then 
      clean $line 
     fi 
    done < /etc/passwd 
else 
    for arg in "[email protected]" 
     do 
     mod $arg 
     done 
fi 
report 

,它不符合正在打印的完整路徑唯一的要求下,#3,報告(只打印相對)。變量t是權限更改將影響的最低uid。將chmod註釋掉了,所以沒有人不小心將它們加入到他們的系統中。哎呀。