Reputation: 591
I'm trying to write a conditional statement so that if a file is greater than 1GB it prints the name of that file, in a file, and skips processing it.
#!/bin/bash
for f in *.dmp
do
if [ ! $(stat -c %s $f > 1000000000) ]; then
name=`basename ${f%.dmp}`
if [ -f ../tshark/$name.dat ]; then
echo "file exists, moving on...";
else
echo "Processing" $name;
tshark -PVx -r "$f" > ../tshark/$name.dat;
echo $name "complete, moving on...";
fi
else
echo $f "too large";
echo $f "\n" > tooLarge.txt;
fi
done
The problem is ! $(stat -c %s $f > 1000000000)
isn't working.
I'd appreciate any suggestions.
Upvotes: 0
Views: 104
Reputation: 1403
So, if you haven't seen the Advanced Bash Scripting Guide, you should. Yes, it's focused around Bash, but it's also a great reference for things like this conditional.
Now, what you've written tries to execute stat -c %s $f > 1000000000
as a command (it's inside the parens on the $()
construct, which is equivalent to the old backtick, as far as I understand. What you want is $(stat -c %s $f) -le 1000000000
which does stat -c %s $f
and then checks if it's less than or equal to 1000000000
. This (i.e., a<=b
) is the equivalent of !(a>b)
logically.
Upvotes: 2
Reputation: 123518
The problem is "! $(stat -c %s $f > 1000000000)" isn't working.
You are including the condition in your command, i.e. within $(...). Say:
"! $(stat -c %s $f) > 1000000000"
Upvotes: 1