It is producing multiple "the file is not correct" messages because that's what you have asked it to do.
Your inner loop ask it to consider every file with for f in `ls *.txt` This could be shortened to just for f in *.txt for a starter, but if you have 30 .txt files, you will get up to 30 the file is not correct messages displayed for that directory.
You then have a bit of an open loop with for i in * which will then drive the for f in loop again and again and again. What happens with any files in the current directory (i.e. not directories in themselves)? I expect that they will error on the cd and then carry on with the for f loop in the current directory.
What is the actual requirement of this part of your code? Maybe I'm missing the point, but you are collecting current date and then the same time for the previous three days and then compare this value to the file names that end .txt in a format I don't understand. Can you explain:-
Is this an "If the value $file is not like the value of $DATEN" or something?
Apologies if I've not learned this syntax yet and it is correct.
Yes. I am trying to compare file to DATEN. I want to get only one printout that says "file not there" and not a printout of "file not there" for each file in each directory. So I want one message per directory.
I'll check out your suggestions as well -- thanks.
That works as well, but I still get multiple messages for each file that does not match the criteria. How do I get one "the file is not there"? I want it to say that the file is not there once for each directory no matter how many files do not match the criteria. I've tried everything and can not figure it out.
Could you change you code so that you keep the outer loop through the list of directories (considering my earlier comment about what happens when for i in * finds a file that it can't cd to)
Inside each directory, you could simply test if the files exist:-
.... which takes out the inner loop and will probably run faster too.
This is how it looks since yesterday (sorry I did not update it earlier). I believe that the -f DATEN and -f DATE2 does not work because I need to compare what truss outputs to the DATEN and DATE2
All I want to do is have it print "file not found: for each directory in which it does not find any matching date. So far it will print that message when any file in any directory does not match the date, so I will get 10 -15 prints in each directory of the message
---------- Post updated at 09:58 AM ---------- Previous update was at 09:47 AM ----------
Also, it would help if I could search on "does the file match the date". would this be
would that mean if the file matchies date 1 or if it matches date2?
---------- Post updated at 10:17 AM ---------- Previous update was at 09:58 AM ----------
Is there a way to echo a message just once and send the rest to /dev/null ?
So that there would be just one message printed for each directory?
---------- Post updated at 11:03 AM ---------- Previous update was at 10:17 AM ----------
also the previous post you made appears to work somewhat:
but it echos yes for everything even though there are no matching files, this
is because I am trying to compare what is in truss command not "do the files exist or not"
This is how it looks since yesterday (sorry I did not update it earlier). I believe that the -f DATEN and -f DATE2 does not work because I need to compare what truss outputs to the DATEN and DATE2
All I want to do is have it print "file not found: for each directory in which it does not find any matching date. So far it will print that message when any file in any directory does not match the date, so I will get 10 -15 prints in each directory of the message
---------- Post updated at 09:58 AM ---------- Previous update was at 09:47 AM ----------
Also, it would help if I could search on "does the file match the date". would this be
would that mean if the file matchies date 1 or if it matches date2?
---------- Post updated at 10:17 AM ---------- Previous update was at 09:58 AM ----------
Is there a way to echo a message just once and send the rest to /dev/null ?
So that there would be just one message printed for each directory?
---------- Post updated at 11:03 AM ---------- Previous update was at 10:17 AM ----------
also the previous post you made appears to work somewhat:
but it echos yes for everything even though there are no matching files, this
is because I am trying to compare what is in truss command not "do the files exist or not"
Yes, you can print one message per directory. But, only if your code only prints one message per directory. Your code prints one message per file.
exits with a zero exit status if the string to which $file expands is identical to the string to which $DATEN expands OR the string to which $file expands is identical to the string to which $DATE2 expands.
Please take a few steps backwards here. We understand that you want to print one message per directory indicating whether or not some condition is met by the files in that directory. What is the condition? Please explain in English what you are trying to determine!
Are you looking for a file whose name is the same as the date on which that file was last modified? (It seems EXTREMELY unlikely that the date on which a file was modified is going to end with the four characters .txt!)
For those of us who don't have truss on our system, what is the output from the command:
when f is set to the name of a text file in the current directory?
Hi,
When I run the the following code:
#!/bin/bash
if ]; then
usage
fi
if ]
then
echo "Do not execute this as root, use -s instead"
fi
SERVERFILE="servers"
function usage {
echo "USAGE: ${0} COMMAND" (4 Replies)
I know, sounds mutually exclusive :-)
I have a script where I ask for a password and store it in a variable, and then use it with sudo on an array of other hosts. The password winds up being choed back to my terminal as well as to the process on the remote host, like:
Attempting to update... (2 Replies)
Hi All,
I want to copy the dir/subdir structure from SERVER-A to SERVER-B without copying all the files in each dir.
Is it possible using SCP / SFTP command?
For example,
SERVER-A has following two dir/subdirectories and files under each subdir.
... (1 Reply)
Hey,
How can I copy files from subdirectories without copy the subdir
and copy it to a higher dir
For example:
/home/test/subdir/file1
copy file1 to /home or another dir
thanx (11 Replies)
I have created a directory structure and under the directory subdirectories and files are there.I need to move the entire thing
to another path.How can i write a script to do that.
currently the path of files is as below :
/data1/serial/mcycle/archive : under this path differnt sub dir exist ... (6 Replies)
Hi,
I m trying to have script to grep a pattern in all files under a directory. I use Sun Solaris, the below want doesnt do exactly what I want.
find /home/xxx/ tagHeu | while read FILE; do
grep text $FILE && echo 1
grep text $FILE || echo 0
done
I also tried running:
find... (2 Replies)
hi:
I have some files like this
folder1/recording1.mp3
folder1/docs/budget.doc
folder2/others/misc.mp3
folder3/others/notes.doc
all this folders and files are under the mp3 folder.
I would like to move just the mp3s to another folder but retain the subdir structure i have.
So if... (4 Replies)
I was just wondering how you would echo out different length variables but still have them all line up. I tried putting tabs between the variables but that didn't work as planned.
For example this is in some loop, with different variables in it each time:
echo "$1 $2 $3 $4 $5"
Appears like... (3 Replies)
Here is the file named tuwork..........
209 200 WZ 6529 SKTNCA01X4X C POI LODI LODI 738 SKTNCA0127T LOD
Here is the scipt.......
cat tuwork |
while
read rva
do
num=`echo $rva | cut -d" " -f1-2`
reg=`echo $rva | cut -c10`
ocn=`echo $rva | cut -c12-15`
x=`echo $rva | cut -c29`... (3 Replies)
Hi all experts,
here is a problem which i would appreciate ur expertise.
I need to do this:
Eg.
Find a number: 1234567 which i dunno which file and which folder
I do know which main folder it is in but it is hidden deep within a lot of subdir.
Is it possible to find the file? + output... (4 Replies)