I have a list of filenames in a particular file. All thse files get generated in the same directory. No w i want to find out which of thse got generated last and capture that time .
Have written a while loop but seems getting struck ...
while read line
do
if [ -e "${line}" ]
then
rvst_capt_time= `ls -lrt $line | awk {'print$7'}`
# here the logic for comparing the modified tome of files should be thr and store into a variable the time of file which gets created last .
#!/usr/bin/env bash
rvst_capt_time=-1
rvst_capt_file=""
while read line
do
if [ -e "${line}" ]
then
last_time=$(stat -c%Y "$line")
if (( last_time > rvst_capt_time)); then
rvst_capt_time="$last_time"
rvst_capt_file="$line"
fi
fi
done <file_list
printf "%s %s\n" "$rvst_capt_file" "$(stat -c%y $rvst_capt_file | sed 's/\..*$//')"
./test.sh: line 12: stat: command not found
./test.sh: line 12: stat: command not found
./test.sh: line 12: stat: command not found
./test.sh: line 12: stat: command not found
./test.sh: line 12: stat: command not found
./test.sh: line 20: stat: command not found
havent haed of the command stat .. though its there on my man page .
Perhaps you could try substituting '/opt/sfw/bin/stat' in case of 'stat' in the script, I don't know. Or wait if other person is able to give you another solution.
./test.sh: line 12: /opt/sfw/bin/stat: No such file or directory
./test.sh: line 12: /opt/sfw/bin/stat: No such file or directory
./test.sh: line 12: /opt/sfw/bin/stat: No such file or directory
./test.sh: line 12: /opt/sfw/bin/stat: No such file or directory
./test.sh: line 12: /opt/sfw/bin/stat: No such file or directory
./test.sh: line 20: stat: command not found
can u pls expalin what stat is ecactly doing so that we can get an alternate commad.