0

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.

3
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by rhousand
0

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

Edited by sknake: n/a

0

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.

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.