yarek
yarek

Reputation: 12064

ssh script to test if date>15 minutes

Someone can help me write a small ssh script to test if file "/usr/modified.txt" has not been modified within 15 minutes, then start a command ./start.sh

Something like:


#!/bin/bash

if [ $date -gt 15 ]

then

/start.sh

fi

Upvotes: 0

Views: 1648

Answers (3)

Phil
Phil

Reputation: 851

#!/bin/bash

if [[ $(find /usr/modified.txt -mmin +15) ]]; then
   ./start.sh
fi

Upvotes: 6

kev
kev

Reputation: 161914

You can use the basic commands date and stat:

#!/bin/bash

x=`stat -c %Y /usr/modified.txt`
y=`date -d '15 min ago' +%s`

if ((x < y)); then
    /path/to/start.sh
fi

Upvotes: 2

user1174838
user1174838

Reputation: 323

@Phil, not quite.

-mtime is for days.

-mmin is for minutes

remember of course that this is with GNU find, which ships with most Linux distros but not all tradional nixes.

Upvotes: 0

Related Questions