I am trying to find the number of files in a directory. I am using the ls command. Based on the Number of Files, I need to display the count and a message. Script doesn't provide the desired output. Any assistance will be appreciated.
#!/bin/sh
FILECOUNT = $(ls /opt/report/ | grep *.ZIP_30 | wc -l);
if [ $FILECOUNT -gt "0" ]; then
echo "Statistic.filecount: $FILECOUNT";
echo "Message.filecount: Normal";
else
echo "Statistic.filecount: $FILECOUNT";
echo "Message.filecount: Warning";
fi;
exit 0;
CodePudding user response:
It's a general advise not to parse the result of ls
, therefore I would advise you the following command:
find /opt/report/ -maxdepth 1 -name "*.ZIP_30" | wc -l
CodePudding user response:
You have a syntax error.
No spaces allowed around =
in shell, so:
filecount=$(grep -c ZIP_30 /opt/report/*)