I have a simple shell script that reads a log of files I've uploaded, and I want to output the file size and line count (less one for the CSV header). I'm looping correctly, but when I try to use find, wc, or stat to get the size of the file it errors out with "No such file or directory". When I try the same command in the terminal, it reports back the size as expected.
fileSizeBytes=$(sudo wc -c "$fileName" | awk {'print $1'})
fileSizeKb=$((fileSizeBytes/1024))
lineCount=$(sudo wc -l "$fileName" | awk {'print $1'})
lineCount=$(($lineCount-1))
the fileName variable contains the full path to the file, and I checked that all users have read/write access. Whether I run with script with my account or as root the result is the same.
wc: /plan/files/Today.csv: No such file or directory
wc: /plan/files/Today.csv: No such file or directory
wc: /plan/files/ERMS_STOCK_05052020.csv: No such file or directory
wc: /plan/files/ERMS_STOCK_05052020.csv: No such file or directory
wc: /plan/files/ERMS_RES_05052020.csv: No such file or directory
wc: /plan/files/ERMS_RES_05052020.csv: No such file or directory
Any ideas what might be causing this? I can a similar script on my Mac (have to change some commands), but on my RHEL 7.7 VM I'm encountering this error.
Cheers