Hello all.
With help on forum i've got the ideia of making the script to check if the file was created today and if its so,print its name.
Here it is:

#!/bin/bash
for file in *; do
        filedate= "date -r $file +%Y-%m-%d"
        currentdate= "date +%Y-%m-%d"
        if["$filedate" == "$currentdate"]; then
        echo $file
fi
done

After reading some tuts, it appers to be parcially valid, but i get the next errors :

./script.sh: line 6: syntax error near unexpected token `then'
./script.sh: line 6: `  if["$filedate" == "$currentdate"]; then'

Thanks in advance.

Recommended Answers

All 4 Replies

Try this:

sk@sk:/tmp$ cat ba.sh
#!/bin/bash
for file in *; do
        filedate=`date -r $file +%Y-%m-%d`
        currentdate=`date +%Y-%m-%d`
        if [ ${filedate} == ${currentdate} ]; then
        echo $file
fi
done
sk@sk:/tmp$ ./ba.sh
ba.sh
sk@sk:/tmp$ touch a b c
sk@sk:/tmp$ ./ba.sh
a
b
ba.sh
c
sk@sk:/tmp$

The script is:

#!/bin/bash
for file in *; do
        filedate=`date -r $file +%Y-%m-%d`
        currentdate=`date +%Y-%m-%d`
        if [ ${filedate} == ${currentdate} ]; then
        echo $file
fi
done

Thanks very much for your help.
It works just grate, but one problem...
When i put it in /etc/cron.daily it doesnt do anything.
The script was changed to next:

#!/bin/bash
for file in /var/www/binaries/*; do
        filedate=`date -r $file +%Y-%m-%d`
        currentdate=`date +%Y-%m-%d`
        if [ ${filedate} == ${currentdate} ]; then
#        echo $file
        `email -s SCAN -b -a $file scan@virustotal.com`
fi
done

It works just fine when i use it, even from the /etc/cron.daily .
Thanks in advance.

Check your /var/log/cron.log

Hello all.
With help on forum i've got the ideia of making the script to check if the file was created today and if its so,print its name.
Here it is:

#!/bin/bash
for file in *; do
        filedate= "date -r $file +%Y-%m-%d"
        currentdate= "date +%Y-%m-%d"
        if["$filedate" == "$currentdate"]; then
        echo $file
fi
done

After reading some tuts, it appers to be parcially valid, but i get the next errors :

./script.sh: line 6: syntax error near unexpected token `then'
./script.sh: line 6: `  if["$filedate" == "$currentdate"]; then'

Thanks in advance.

How about a one liner.

find ./ -type f -mtime -1

Find will list any files less that one day old it the current directory.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.