Bash script, need help with
+1
A:
Instead of specifying $1 $2 $3, loop over the inputs like so:
for user ; do
Then, you will need to change all $1 to $user
Bruce Armstrong
2010-10-28 17:56:35
You almost never want `$*`. Use `"$@"` instead. Or just remove the sequence to iterate over entirely; the default for `for` is `$@`.
Ignacio Vazquez-Abrams
2010-10-28 18:06:48
I hadn't realized the difference between the variables. I'll update to reflect that.
Bruce Armstrong
2010-10-28 18:27:49
Do u mean it should be like:
trs
2010-10-28 18:39:32
You won't need the shift before done, aside from that, its better. Although, please reformat the code to display as code.
Bruce Armstrong
2010-10-28 18:53:31
+3
A:
code from the initial post seems to have disappeared... rolled up an example.
#!/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 "$@"
do
mod $arg
done
fi
report
only requirement that it doesn't meet is printing full path (only prints relative) under #3 in the report. the variable t is the lowest uid the permissions changes will affect. commented out the chmods so no one accidentally does this to their system. oops.
Orbit
2010-10-28 20:54:49