LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   script to show if file exists (https://www.linuxquestions.org/questions/linux-newbie-8/script-to-show-if-file-exists-849862/)

ltodd2 12-13-2010 02:40 AM

script to show if file exists
 
Morning all
Im not sure if this is the correct place to ask this or not.

I have a script that runs each day at 6am and looks for files created within the last day and outputs the text to a file which it emailed to me. Im wanting to change it so that it would say something like "phone system backup complete" or "websense back complete" and say fail if its not there.

Below is an example of what output I get sent and below that the script. If anyone can help I would be grateful. I think its any easy thing but being new to scripting and not programmed before im a bit lost and google is not helping me much.

Dec 13 02:27 /mnt/ukwcs-net-config/IPT/Backup12-13-10#2-20.tar
Dec 13 01:00 /mnt/ukwcs-net-config/Websense/wsbackup_2010-12-13_010000.tar.gz

Script:
find /mnt/ukwcs-net-config -mtime -1 -ls | egrep '(.dmp|.tar.gz)' > log.txt
find /mnt/ukwcs-net-config -mtime -1 -ls | egrep '(/IPT/)' > logi.txt
find /mnt/ukwcs-net-config -mtime -1 -ls | egrep '(.agb)' > loga.txt
find /mnt/ukwcs-net-config -mtime -1 -ls | egrep '(canit-spam)' > logc.txt
find /mnt/ukwcs-net-config -mtime -1 -ls | egrep '(172.16.100.20)' > logt.txt
sed '$!d' logt.txt >> log.txt

echo >> send.txt
echo ----------------------------------------------------------------------------------------------------- >> send.txt
echo Backup log from netmon. >> send.txt
echo ----------------------------------------------------------------------------------------------------- >> send.txt
echo >> send.txt
echo >> send.txt

cut -c 1-62 --complement logi.txt >> send.txt
cut -c 1-57 --complement log.txt >> send.txt
cut -c 1-58 --complement loga.txt >> send.txt
cut -c 1-60 --complement logc.txt >> send.txt

mail -s "Network Backup Files" ltodd2 < send.txt


Many thanks

Lee

barriehie 12-13-2010 05:44 AM

I don't totally understand the ?. If you're wanting to test for a files existence then:
Code:

if [ -f /some_path/some_file ]
then
  ...some_file exists so do something...
else
  ...some_file doesn't exist so do something else...
fi


catkin 12-13-2010 07:51 AM

It is difficult to understand from the OP what you want to do.

The finds section could be tidied up (functionally the same, not tested) to:
Code:

find /mnt/ukwcs-net-config -mtime -1 -type f -name '*.dmp*' -o -name '*.tar.gz*' -ls > log.txt
find /mnt/ukwcs-net-config -mtime -1 -path '*/IPT/* -ls > logi.txt

and similar, with the * omitted from .dmp* if .dmp is the end of the file name.

Why the different column ranges in the cut commands?

If you want to identify missing files the you need a list of expected files to compare with the files found ... ?


All times are GMT -5. The time now is 09:11 PM.