Im looking to write a script to check if a file exists and if it doesnt then send an email out, Ive found the below code but I don't understand the ! in the if statement can anyone explain?
Any help will be much appreciated
#!/bin/bash
if [ ! -s filename ]
then
echo "File not exists" | mailx -s "File Not found" abc@xyz.com
else
echo "File exists"
fi
Got the below script now, but getting the error message
/export/home/tjmoore/file_checker: line 4: [: -s: binary operator expected
#!/bin/bash
#Script to check if a file exists and if not send an email alert out
#
if [ test -s /export/home/tjmoore/file6 ]
then echo "File does not exist" | mailx -s "File not found" <email address> <email address>
fi
Dont know why but this doesnt seem to work, possibly something to do with me not using the mailx command properly?
#!/bin/bash
#Script to check if a file exists and if not send an email alert out
#
if [ ! -f /export/home/tjmoore/file6 ]
then
echo "File does not exist" | mailx -s "File not found" <Send email address> <Receive emal address>
fi