The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
help wid C-script in tcsh mahendrakamath High Level Programming 12 11-28-2007 01:12 PM
tcsh I can't get script to work :( Fred Goldman Shell Programming and Scripting 8 11-12-2007 05:44 PM
help in tcsh mahendrakamath UNIX for Dummies Questions & Answers 3 11-12-2007 04:05 PM
how to call a perl script from tcsh? megastar Shell Programming and Scripting 1 10-22-2005 06:48 PM
tcsh kartik Shell Programming and Scripting 1 10-20-2004 06:05 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-09-2007
kumarsaravana_s kumarsaravana_s is offline
Registered User
  
 

Join Date: Feb 2007
Location: Bangalore
Posts: 105
Help me with this tcsh script.!!!!(Anbu)

I need to write a tcsh script which would compare files in the two folders and then send me a mail saying which of the files are missing.For eg

1) I have this folder1 containing all the files which must land on folder2 on a daily basis.

2) If a file is present in folder1 but not in folder2,then a email must be sent to me saying which file is missing in folder2.

for instance,

Folder 1 has(it has some 103 files to be precise)

aaa
bbb
ccc
ddd
ccc
eee
fff

folder2 has(the same file name but with a daily time stamp attached to it.So need to remove this date portion and then compare the files in folder2 with files in folder1

aaa.03082007
bbb.03082007
ccc.03082007
ddd.03082007


So the script must inform me that eee and fff files are missing...

I want this whole process to be inside a loop and somewhat automated so that i dont have to run the script daily manually.

your help will be greatly appreciated....

Thanks
Kumar

Last edited by kumarsaravana_s; 03-12-2007 at 05:45 AM..
  #2 (permalink)  
Old 03-09-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
cd /dir/folder1
for i in *
do
	if [ -f ./$i -a ! -f /dir1/folder2/${i}"."* ]; then
		echo "$i file not found"
	fi
done
  #3 (permalink)  
Old 03-09-2007
dennis.jacob dennis.jacob is offline Forum Advisor  
dj - the student
  
 

Join Date: Feb 2007
Location: Singapore/Bangalore/Cochin
Posts: 607
dir1=$(ls directory1)
dir2=$(ls directory2)
for i in $dir1
do
$(echo $dir2 | grep -q $i)
[[ $? -ne 0 ]]&& echo $i
done
  #4 (permalink)  
Old 03-09-2007
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,554
Quote:
Originally Posted by jacoden
dir1=$(ls directory1)
dir2=$(ls directory2)
for i in $dir1
do
$(echo $dir2 | grep -q $i)
[[ $? -ne 0 ]]&& echo $i
done
its easier to read using code tags
  #5 (permalink)  
Old 03-09-2007
cfajohnson's Avatar
cfajohnson cfajohnson is offline Forum Advisor  
Shell programmer, author
  
 

Join Date: Mar 2007
Location: Toronto, Canada
Posts: 2,361
Quote:
Originally Posted by kumarsaravana_s
I need to write a tcsh script which would compare files in the two folders and then send me a mail saying which of the files are missing.For eg
Don't use [t]csh for scripting. See:

CshTop10
Csh
csh-whynot

Quote:
1) I have this folder1 containing all the files which must land on folder2 on a daily basis.

2) If a file is present in folder1 but not in folder2,then a email must be sent to me saying which file is missing in folder2.

for instance,

Folder 1 has(it has some 103 files to be precise)

aaa
bbb
ccc
ddd
ccc
eee
fff

folder2 has(the same file name but with a daily time stamp attached to it.So need to remove this date portion and then compare the files in folder2 with files in folder1

aaa.03082007
bbb.03082007
ccc.03082007
ddd.03082007


So the script must inform me that eee and fff files are missing...

I want this whole process to be inside a loop and somewhat automated so that i dont have to run the script daily manually.
Code:
is_file()
{
    for f
    do
       [ -f "$f" ] && return
    done
    return 1
}

cd Directory1
for file in *
do
   is_file "Directory2/$file"* || printf "%s not found\n" "$file"
done
To run it regularly, put the script in a cron job.

Last edited by vgersh99; 03-09-2007 at 03:31 PM.. Reason: fixed the URL links with the vB Codes
  #6 (permalink)  
Old 03-12-2007
kumarsaravana_s kumarsaravana_s is offline
Registered User
  
 

Join Date: Feb 2007
Location: Bangalore
Posts: 105
Hi Anbu

i dont know but your seems to just display file not found all the time...

let me make myself more clear...

1st folder = /space/dwland/all_files/

Now,this folder has files like xxx.<file_name>,bbb.<file_name> and so on

2nd folder = /space/dwland/prodland/

now this folde has files like xxx.<file_name>.<date>,bbb.<file_name>.<date>, and so on..

I want to compare 1st folder with 2nd folder(-minus the date portion,for the file_names should be compared) and display the files which are not present in folder 2 but present in folder 1
  #7 (permalink)  
Old 03-12-2007
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
Code:
$ ls ./folder1
aaa  bbb  ccc  ddd  eee  fff
$ ls ./folder2
aaa.03082007  bbb.03082007  ccc.03082007  ddd.03082007
$ cd folder1
$ for i in *
> do
>       if [ -f ./$i -a ! -f /dir1/folder2/${i}"."* ]; then
>               echo "$i"
>       fi
> done
eee
fff
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:11 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0