made a script and it works for linux but not for mac, here it is
#!/bin/bash
echo "please enter in the location where you want the log files to be saved (press tab to auto-complete)"
read -e log
echo "please enter in minutes how long you want to monitor disk usage, this excludes remote file systems"
read min
echo "please wait while I monitor disk usage"
hn=$(hostname)
dt=$(date "+%y%m%d%H%M")
df1=$log/disk_usage/$hn/$dt.df1.txt
df2=$log/disk_usage/$hn/$dt.df2.txt
loc=$log/disk_usage/$hn/$dt.loc.txt
list=$log/disk_usage/$hn/$dt.list.txt
mkdir -p "$log"/disk_usage/"$hn"
past=$(date "+%y-%m-%d %H:%M:%S")
df -l > "$df1" && sleep "$min"m
df -l > "$df2"
diff "$df1" "$df2" | awk '{print $7}' | sort | uniq > "$loc"
sed -i '/^$/d' "$loc"
sed -i '/Mounted/d' "$loc"
pres=$(date "+%y-%m-%d %H:%M:%S")
while IFS= read -r line; do
find $line -newerat "$past" ! -newerat "$pres" -type f -exec ls -lah {} + >> "$list"
done < "$loc"
echo "the log can be found below"
echo ""$log"/disk_usage/"$hn"/"$dt".list.txt"`
the commands that dont work on mac when i run the script are
sed -i '/^$/d' "$loc"
find $line -newerat "$past" ! -newerat "$pres" -type f -exec ls -lah {} + >> "$list"
why dont these work as i thought there unix commands?
I edited your code sample iwth the proper use of the markdown tags. Please be careful next time.
When you say "it works for linux but not for mac", in what way don't they work?
Any error messages? Wrong results?
have you tried running your script with the set -x enabled?
P.S. most likely your Linux based script takes advantages of the GNU functionality/extensions to some of the basic tools (e.g. sed and find) which don't exist in the other non-GNU distributions.
For multi-line code the markdown tags must be on separate lines. Please use the icons at the top of the editor to place proper markdowns!
You must use -prune to not descend into it, -path descends (running into the "access denied") then filters. -prune is true when it prunes, so you must continue with -o (or, otherwise) for all the other items.
(And if you have further -o you need \(\). The simply chained conditions use implicit -a at a higher precedence)
find / -ipath "/private" -prune -o -newerat 20-06-19 ! -newerat 20-06-19 -type f -exec ls -lah {} \;
Yes that should work, but one -o seems to be missing.
Note if you do not have an explicit action, there is an implicit -print action for each -o branch.
And you only need to prune=skip a process tree once so -path /proc skips only this (not a /proc1 or a /processes)
And with paranthesis you can make it shorter (need to be escaped for the shell)
echo "please enter in the location where you want the log files to be saved, make sure you start it with "/" (press tab to auto-complete)"
read -e log
hn=$(hostname)
dt=$(date "+%y%m%d%H%M%S")
df1=$log/disk_usage/$hn/$dt.df1.txt
df2=$log/disk_usage/$hn/$dt.df2.txt
changes=$log/disk_usage/$hn/$dt.changes.txt
list=$log/disk_usage/$hn/$dt.list.txt
echo "any folders you DONT want me to monitor,just leave a space between the folders and remove the last "/" for all folders (up to five x5)"
read -e path1 path2 path3 path4 path5
echo "please enter in minutes how long you want to monitor disk usage"
read min
echo "please wait while I monitor disk usage"
mkdir -p "$log"/disk_usage/"$hn"
past=$(date "+%y-%m-%d %H:%M:%S")
df -l > "$df1" && sleep "$min"m
df -l > "$df2"
diff "$df1" "$df2" | awk '{print $7}' | sed '/Mounted/d' | sed '/^$/d' | sort | uniq > "$changes"
pres=$(date "+%y-%m-%d %H:%M:%S")
while IFS= read -r line; do
find $line -path "$path1" -prune -o -path "$path2" -prune -o -path "$path3" -prune -o -path "$path4" -prune -o -path "$path5" -prune -o -newerat "$past" ! -newerat "$pres" -type f -exec ls -lah {} \; >> "$list"
done < "$changes"
echo "the log can be found below"
echo ""$log"/disk_usage/"$hn"/"$dt".list.txt" ```
echo "any folders you DONT want me to monitor,just leave a space between the folders and remove the last / for all folders"
read -e paths
# we use unquoted variables to let the shell split their contents on whitespace.
# -f disables further expansions
set -f
fpaths=
for p in $paths
do fpaths+="${fpaths:+-o} -path $p"
done
(The :+ variable modifier puts the following string if the variable is not empty. Much more elegant than an if statement.)