LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 12-13-2010, 02:40 AM   #1
ltodd2
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

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
 
Old 12-13-2010, 05:44 AM   #2
barriehie
Member
 
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:
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
 
Old 12-13-2010, 07:51 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
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:
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 ... ?
 
  


Reply


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 03:31 PM
shell script to delete a file if it exists tkmsr Programming 11 08-10-2010 07:30 AM
ls -a doesn't show the file that exists pratapmaddi Linux - Newbie 3 09-10-2009 09:31 AM
Shell script problem. check file already exists sinister1 Linux - Server 8 11-20-2007 03:13 PM
SIOCADDRT: File exists SIOCCADDRT: File Exists Failed to bring up eth0. opsraja Linux - Networking 0 01-10-2005 08:29 AM


All times are GMT -5. The time now is 08:54 PM.

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