On Wednesday 09 August 2006 13:17, Phill Coxon wrote:
> Hi,
>
> ** Can someone tell me how to detect if a file exists using bash?
>
> I need to check for the file periodically (via cron) and if it
> disappears, copy a backup of the file to replace it.

#!/bin/bash
if [ -f the.file ]; then
        echo "File exists"
fi

> I have a client with a dedicated server where a very important
> configuration file keeps disappearing for no explainable reason.
>
> So we need a script to regularly check every that the file is there and
> replace it when it disappears so that his web site services keep
> running.
>
> As to why it's disappearing...no idea.  I'm starting to suspect it may
> be malicious code that a previous programmer installed to delete the
> config file so he would pick up the "maintenance" work.  I've had a good
> look around but haven't found anything yet.
>
> Which leads to a second question:
>
> ** Is there any way to monitor a file and log which processes or scripts
> access and / or modify it?

Not off the top of my head but if you have root the you could `chattr +i 
the.file` and then the process that's trying to delete it will bork.

hads

-- 
http://nicegear.co.nz
New Zealand's VoIP supplier

Reply via email to