PDA

View Full Version : Help with bash


George Hallam
11-15-2011, 09:32 AM
Im trying to write a program in bash that will return (print out to screen)
0 if the file i inputted exists and was modified within the past 20 mins
1 if the file i inputted exists and was not modified within the past 20 mins
2 the file i inputted does not exist

the file i input will be enter as a 1st command line argument after the code

i know that i have to use find -mmin -20 and that will return the files name if it was modified within the past 20 mins, but i cant get it to output just a 0 r a 1 =/

any ideas

yawningdog
11-30-2011, 03:28 PM
This will get the job done I believe, although it doesn't use find -mmin -20.
#!/bin/bash
if [ -e $1 ]
then
echo $(( (`date +%s` - `stat -L --format %Y $1`) > (20*60) ))
else
echo 1
fi