Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 12-13-2010, 03:40 AM   #1
LQ Newbie
Registered: Aug 2005
Posts: 28

Rep: Reputation: 0
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

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 '(' > 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

Old 12-13-2010, 06:44 AM   #2
Registered: Nov 2010
Distribution: Debian Lenny
Posts: 136
Blog Entries: 1

Rep: Reputation: 23
I don't totally understand the ?. If you're wanting to test for a files existence then:
if [ -f /some_path/some_file ]
  ...some_file exists so do something...
  ...some_file doesn't exist so do something else...
Old 12-13-2010, 08:51 AM   #3
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,577
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
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:
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 ... ?


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script automatic file rename if exists AutoC Programming 4 06-23-2015 04:31 PM
shell script to delete a file if it exists tkmsr Programming 11 08-10-2010 08:30 AM
ls -a doesn't show the file that exists pratapmaddi Linux - Newbie 3 09-10-2009 10:31 AM
Shell script problem. check file already exists sinister1 Linux - Server 8 11-20-2007 04:13 PM
SIOCADDRT: File exists SIOCCADDRT: File Exists Failed to bring up eth0. opsraja Linux - Networking 0 01-10-2005 09:29 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:21 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration