Ok. So here is the situation.
I scan to an ftp folder. I want to know if new files have appeared in that folder using the following program code. The number of lines output to count.txt is 3, the reason being one of the files is .ftpquota.
so if I run this from the command line
ls -1 ~/public_html/scan | wc -l > count.txt
and then run the script
#!/bin/bash
var=$(cut -d, -f1 count.txt)
echo "No of files is $var"
if [[ "$var" -gt 3 ]]
then
printf "Found new documents...\n"
else
printf "No new documents found.\n"
fi
The program works fine because value of $var is 3. But my problem is that because I would like to include this line
ls -1 ~/public_html/scan | wc -l > count.txt
as a part of the script so that it updates count.txt everytime, it does not work. So in other words if I do this:
#!/bin/bash
ls -1 ~/public_html/scan | wc -l > count.txt
var=$(cut -d, -f1 count.txt)
echo "No of files is $var"
if [[ "$var" -gt 3 ]]
then
printf "Found new documents...\n"
else
printf "No new documents found.\n"
fi
It breaks the script and it stops working and $var returns a value of 0 .Please help. I would like this code corrected instead of being given alternative solutions. I spent days on this script and now I'm almost there if that one command works.