I'm lost what you are trying to achieve. On the files you are searching for, are you just after matching them on a date? I've very confused.
Your DATEN, DATE2 etc. values will be the string for the date in the format Mmm dd YYYY where dd is padded with a leading space if required. This matches the output from ls -l when a file is older than 6 months, but a truss gives me no output.
Perhaps we should start again with the logic.
Are you looking for files that match a date-stamp? There are easier ways with the find command.
How many files must you find in a particular directory to regard it as a success? I'm guessing that it could be zero, 1, 2, 3 or 4.
Is there a reason that you compare every file that matches *.txt one at a time? It reads the directory for every file you match. it would be quicker to read the directory for the files you want or read it once and scan the output. What is your matching criteria?
This date is supposed to be matched against files in each directory:
Dir1
file1--checks truss date against file date
file2
file3
Dir2
filea
fileb
filec
What happens is that it checks every file and so it prints out a message for every file. What I want it to do is print one message for each directory. The message should say "Not found" for any directory that does not have at least one file that matches the date in truss command.
But it prints a message for each file that does not match, because it is not written correctly.
I really don't want to use the find command, this is an experiment with truss and loops for myself .
So is the date part of the file name or the last modified time?
If it's part of the file name try variations on:-
The logic will be true if a file name containing the first or second or third or fourth date exists in the current directory.
If you are looking for a file modified on the correct date, then that's tricker, however you could try variations on:-
You may need to add a -prune clause if there are subdirectories you don't want to search down.
Using commands like ls -l to show the directory of files including their last modification date/time is problematic because the date format for files modified within the last 6 months is Mmm dd HH:Mi
If you don't want to use find then I'd have to ask why. It's probably the right tool for the job. Never screw something in with a hammer. If you want to go a bit Heath-Robinson then I'm out.
Of course, if I've missed the point then let me know.
What is the point of the truss command anyway? I'm most confused over that I think.
This date is supposed to be matched against files in each directory:
Dir1
file1--checks truss date against file date
file2
file3
Dir2
filea
fileb
filec
What happens is that it checks every file and so it prints out a message for every file. What I want it to do is print one message for each directory. The message should say "Not found" for any directory that does not have at least one file that matches the date in truss command.
But it prints a message for each file that does not match, because it is not written correctly.
I really don't want to use the find command, this is an experiment with truss and loops for myself .
No! It is not! That is the output of a perl command; not the truss command that I asked for:
when f is set to the name of a text file in the current directory? PLEASE SHOW US THE OUTPUT FROM THE ABOVE COMMAND!
From the commands following truss in your pipeline we know that the output from truss has to be at least four lines.
And you still have not told us what you are trying to do! WHAT CHECK ARE YOUR TRYING TO PERFORM BETWEEN FILES IN A DIRECTORY AND YOUR FOUR DATES?
Are you trying to check whether the name of a file in a directory is one of your date strings? (This is what your current code is doing! And, we know it is doomed to fail: a date string ending in "2014" can never be a filename ending in ".txt"!)
Are you trying to check whether or not one of the date strings is part of the name of a file in a directory?
Are you trying to check whether or not the date on which the file was last read matches one of the date strings?
Are you trying to check whether or not the date on which the file was last modified matches one of the date strings?
Are you trying to check whether or not the date on which the file status was last modified matches one of the date strings?
Are you simply trying to determine whether or not any file in a directory has been modified since midnight four days ago?
Are you simply trying to determine whether or not any file in a directory has been modified in the last 96 hours (24 hours/day * 4 days)?
If you can't clearly explain what you are trying to do in unambiguous terms, we can't help you.
These 2 Users Gave Thanks to Don Cragun For This Post:
Thanks all, for your suggestions. I finally did make this work. I still used truss, and needed some awk as well, but I got it to do what I wanted by carefully inspecting each line of the script.
Thanks all, for your suggestions. I finally did make this work. I still used truss, and needed some awk as well, but I got it to do what I wanted by carefully inspecting each line of the script.
If you will show us the output you get from running truss and show us your current working script, there is a good chance we can help you make it more efficient.
It will also help other people reading this thread in the future figure out how you solved your problem.
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)