Visit Our UNIX and Linux User Community


Help me with this tcsh script.!!!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help me with this tcsh script.!!!!
# 1  
Old 03-09-2007
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 06:45 AM..
# 2  
Old 03-09-2007
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  
Old 03-09-2007
dir1=$(ls directory1)
dir2=$(ls directory2)
for i in $dir1
do
$(echo $dir2 | grep -q $i)
[[ $? -ne 0 ]]&& echo $i
done
# 4  
Old 03-09-2007
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  
Old 03-09-2007
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  
Old 03-12-2007
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  
Old 03-12-2007
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


Previous Thread | Next Thread
Test Your Knowledge in Computers #967
Difficulty: Medium
The 'video' and 'audio' elements for multimedia content were deprecated in HTML5.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Regular expressions in tcsh script

Hi, I have a shell script in tcsh to which I pass an argument, the length of which can vary. The possible values of the argument are the letters -c,s,i,q,a. and also a combination of these letters. (e.g: cs,si,ca,iq,qa,csq,acs,csia ..etc). The order of the letters does not matter. My problem... (2 Replies)
Discussion started by: Vaisakh P
2 Replies

2. Shell Programming and Scripting

Tcsh complete (autocomplete) script

I cant figure out how the complete function works in tcsh. 1. I whould like it to complete after writing my_program.py with either start or stop. I have tried to do something like this in .cshrc.user: complete my_program.py \ 'c/start/' \ 'c/stop/' However i cant get it to... (1 Reply)
Discussion started by: mr_cad
1 Replies

3. Shell Programming and Scripting

Help in tcsh script

Hi All, I wrote a tcsh script, but being a beginner it took me lots of efforts and on top of that I am still struggling with little modifications here and there. kindly have a loop. Line1 : I want it to run maximum of "Max" Which I am providing outside loop. So how the "for" should be... (10 Replies)
Discussion started by: nrjrasaxena
10 Replies

4. Shell Programming and Scripting

tcsh env setting using shell script

Hi All, I have made a file file usercreate.sh & it has to run in tcsh env & needs some path to be set. my script is as below. ########################## #!/bin/csh setenv PATH "/usr/lib/java/class" setenv LD_LIBRARAY_PATH ########################### but when i am ruuning my script... (1 Reply)
Discussion started by: ajaincv
1 Replies

5. Shell Programming and Scripting

[Basic Query]bsh script in tcsh shell

I am a beginner (Just 2 days old:o ), i will really appreciate if you can solve my silly queries as below: Lets say i write a script like this #!/bin/bsh clear #to read name from keyboard echo "your name please.." read fname echo "you just entered $fname" exit 0 My environment is... (2 Replies)
Discussion started by: animesharma
2 Replies

6. Shell Programming and Scripting

Help with gawk array, loop in tcsh script

Hi, I'm trying to break a large csv file into smaller files and use unique values for the file names. The shell script i'm using is tcsh and i'm after a gawk one-liner to get the desired outcome. To keep things simple I have the following example with the desired output. fruitlist.csv apples... (6 Replies)
Discussion started by: theflamingmoe
6 Replies

7. Shell Programming and Scripting

tcsh: not run script (if: Badly formed number)

Hello I have Linux Debian & tcsh shell. My mini script not run :(. Startup script displays a message: user@host:dir% ./test if: Badly formed number. script: #!/bin/tcsh -f #script check size files systems set x = `df -h /usr | tail -n1 | awk '{ print( $5 ); }'` set y = 60% if ($x... (5 Replies)
Discussion started by: moskovets
5 Replies

8. Programming

help wid C-script in tcsh

Hello Freinds I have just started off with Unix (TCSH) although I have a pretty sound background with C-programming. Kindly convey any error in foll script. #include<stdio.h> #include<math.h> #define PI 3.142857 main () { float r, A; printf("Enter the value of radius: "); scanf(" %f... (12 Replies)
Discussion started by: mahendrakamath
12 Replies

9. Shell Programming and Scripting

tcsh I can't get script to work :(

I have an export utility that exports documents from the native file to text. This is the way I would run it from the command line: expage "file" > "file.txt I am trying to loop through all the documents in the directory and expage them, here is the code: #!/usr/bin/env tcsh foreach file... (8 Replies)
Discussion started by: Fred Goldman
8 Replies

10. Shell Programming and Scripting

how to call a perl script from tcsh?

Hi I am not sure how to call a perl script from a tcsh shell. do i need to set any environment variables? your help is appreciated Thanks (1 Reply)
Discussion started by: megastar
1 Replies

Featured Tech Videos