Visit Our UNIX and Linux User Community

Daily File Checks

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Daily File Checks
# 1  
Old 06-08-2011
Daily File Checks

Hello all,

I'm sorry if this is answered elsewhere, I've used the search function and can't find the specifics of what I'm after.

I am brand new to playing with linux, and ideally I want to get better to help the company that I now work for.

What I want to do:
Create a script that I can run daily to check for differences from today to yesterday on my linux server.

My Idea
Use a DF command and record the information from it in a file named size_DDMMYY
Search for every file/folder name on the linux server and write them to a file named linux_DDMMYY
Compare yesterdays size_DDMMYY to todays size_DDMMYY and write the size difference to a file named sizeDiff_DDMMYY
Compare yesterdays linux_DDMMYY to todays linux_DDMMYY and write the difference (new files added, old files deleted) to a file named linuxDiff_DDMMYY

My problem:
At the moment I haven't written any code down, I'm just writing/testing ideas on how to go about this. I've been playing with the diff command but have hit a brick wall. It appears that the diff command compares:
line1 in file1 to line1 in file2 and
line2 in file1 to line2 in file2 etc.

If my linux_DDMMYY output file has new files added to it or old files removed, the diff command would be ineffective (due to line checking not string checking)

What I want it to do(i think) is grab the string from line1 in file1 and search file2 for the same string and then move to the next line in file1 etc.

At the moment I've concluded that using a diff command isn't going to help, i've gone through the other commands that can be used with diff but have yielded no ideal results.

Any help or insight would be greatly appreciated.

Thanks in advance,

Last edited by Aussiemick; 06-08-2011 at 01:07 AM..
# 2  
Old 06-08-2011
For you idea - it's better to use find:
To find all files modified between 24 and 48 hours ago in DIRECTORY and its suddirectories:
find DIRECTORY -ctime 1 -type f

To find all the files that were modified yesterday from the current working directory and all of its subdirectories:
find . -daystart -ctime 0 -type f

For your problem - it's possible to use associative arrays from any scripting language - look for "Finding Elements in One Array but Not Another" on PLEAC in chapter 4 "Arrays".
This User Gave Thanks to yazu For This Post:
# 3  
Old 06-08-2011
Originally Posted by yazu
For you idea - it's better to use find:
To find all files modified between 24 and 48 hours ago in DIRECTORY and its suddirectories:
find DIRECTORY -ctime 1 -type f

I don't appear to get an output when I run this?

Originally Posted by yazu
To find all the files that were modified yesterday from the current working directory and all of its subdirectories:
find . -daystart -ctime 0 -type f

Just wondering if I'm able to get a datestamp and filesize in the output?
Either way this is very useful, adding > filename to the end allowed me to save it in a file.

Thanks very much : )

P.S. i tried adding -al and -l on the end of find . -daystart -ctime 0 -type f but got an error saying "invalid predicate"
# 4  
Old 06-08-2011
You can pipe so:

find ... | xargs ls -l

This User Gave Thanks to yazu For This Post:
# 5  
Old 06-08-2011
Thanks heaps, I'm not real familiar with this sorta thing as you may have noticed Smilie but I learnt a new terminology, pipe. ^.^

Not to push your good will, but now that I have files being updated with the relevant information, is there any language you'd suggest to create an array to compare two lists?
Ideally I just want to compare the difference between the size of the same file from one day to the next. As a newbie programmer, arrays have always been less than friendly towards me.

Previous Thread | Next Thread
Test Your Knowledge in Computers #793
Difficulty: Easy
The base-2 numeral system is a positional notation with a radix of 3.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to move file on a daily basis

Hi! Please I need help on the a script that would pick one file in a directory, change its name, them change its permissions, them move to a different directory, but has to be done on a daily basis, and the file that is being moved to its final destination has to have the following format:... (7 Replies)
Discussion started by: fretagi
7 Replies

2. Shell Programming and Scripting

How to send file from windows to UNIX daily?

Hi All! I am trying to write a little script that should go to a windows server get one file and put on a unix server, but I am not sure if it is the right way please help: #! /usr/bin/sh HOST= USER=ftp_hm PASSWD=P@$$w0rd ftp -n $HOST quote user $USER quote pass $PASSWD... (7 Replies)
Discussion started by: fretagi
7 Replies

3. Red Hat

UNIX script for daily file transfer ???

I need to create a script which needs to transfer the "<filename>+yyyymmdd".dat file from a unix machine to a linux machine.. daily. we can use an active batch to schedule the script. however, the script needs to detect if the new file is present, if present, then transfer. any help ?? (1 Reply)
Discussion started by: ravikodi
1 Replies

4. Shell Programming and Scripting

Daily Checks

Hey Guys, I'm seeking some assistance in getting this script to run as a cron job for the user oracle.. the script is basically to perform 2 ADRCI checks... see the script below... i'm getting the following error: /export/home/oracle/Daily_Checks/ syntax error at line 16:... (7 Replies)
Discussion started by: Racegod
7 Replies

5. Shell Programming and Scripting

Daily grep on a log file

Hi, I would like to execute a daily grep like: grep 2010-09-06 statistics.log|grep API > /var/tmp/stat20100906_sp.txt On date e.g. 2010-09-07 run a grep on yesterday's date, from the result grep the word "API" put all in /var/tmp Would like to have a script configured in the crontab, running... (4 Replies)
Discussion started by: pointer
4 Replies

6. AIX

Daily checks for AIX business critical boxes.

Hi all, I will like to know what are all sanitary checks which should be done on daily basis on all business critical AIX boxes without fail. (7 Replies)
Discussion started by: deepm
7 Replies

7. UNIX for Advanced & Expert Users

speed test +20,000 file existance checks too slow

Need to make a very fast file existence checker. Passing in 20-50K num of files In the code below ${file} is a file with a listing of +20,000 files. test_speed is the script. I am commenting out the results of <time test_speed try>. The normal "test -f" is much much too slow when a system... (2 Replies)
Discussion started by: nullwhat
2 Replies

8. UNIX for Advanced & Expert Users

Doing Checks on a file

I have a process that I am trying to provide a solution for and have hit a brick wall and would like some pointers in the right direction. Basically on a daily basis a report is automatically generated in a CSV format (FIRST.CSV) which includes codes and amounts in the following format: ... (6 Replies)
Discussion started by: SAMZ
6 Replies

9. Shell Programming and Scripting

perform some checks on file using perl

hi i want check for PVCS header in file if its present then check if its in proper format or not i want to do this is in perl on windows. this is what i am doing : 1 . open file 2 . check for "PVCS information" if found then store the line no to $line var. 3 . check for "sccs" header ... (0 Replies)
Discussion started by: zedex
0 Replies

10. Shell Programming and Scripting

monitor daily file uploads

hey all, i am a shell scripting n00b so bear with me. i got a server that every night uploads one file to a remote server. the file is prodserver_date_time. i would like to make a script, run by root on a daily cron job. i want it to determine if the file was received or not. no md5... (2 Replies)
Discussion started by: jweinraub
2 Replies

Featured Tech Videos