- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: To pass comments on a script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-12-2005 04:24 AM
тАО10-12-2005 04:24 AM
To pass comments on a script
I have this script that runs everyday to Long list (ll in HPUX and ls -la in Solaris)all the files in all the directories.The Script when runs the nextday , captures the difference between previous day's longlist(ll) and currentday longlist (ll) using the diff command in HPUX "diff file1 file2 > file12"] and save it to new file titled "result".
The Result file looks like this
-rw-r--r-- 1 root sys 48 Sep 17 09:32 see
drwxr-xr-x 3 root sys 96 Sep 17 08:58 tde5
drwxr-xr-x 2 root sys 96 Sep 17 08:57 tse4
-rw-r--r-- 1 root sys 30 Sep 17 09:32 ree
There are 9 fields in the "result" output file.
Now I want to pass comments (like change in file owner or change in permission) for every file if there is any change in any of the fields of the file.
Can you please suggest me a way to do it and that would fit to my below mentioned script.
The script is as follows:
#! /usr/bin/sh
dt1=`date`
TODAY=`echo $dt1|cut -d" " -f3`
set -A DAYS Sat Sun Mon Tue Wed Thu Fri Sat
set -A MONTHS Dec Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
YESTERDAY=$((`date +%d` -1))
MONTH=`date +%m`
YEAR=`date +%Y`
NDAY=`date +%u`
tfile=$MONTH$TODAY$YEAR.lst
echo $tfile
WEEKDAY=${DAYS[`date +%u`]}
if [ $YESTERDAY -eq "0" ]
then
MONTH=$((MONTH-1))
if [ $MONTH -eq "0" ] then
MONTH=12
YEAR=$((YEAR-1)) fi
set `cal $MONTH $YEAR`
shift $(($# - 1))
YESTERDAY=$1
fi
TMONTH=${MONTHS[MONTH]}
yfile=$MONTH$YESTERDAY$YEAR.lst
echo "Y day File Name " $yfile
echo "T Day file Name " $tfile
ls -ltR /home/tmp >$tfile
diff $tfile $yfile >result.chg
Thanks for your help.
Thanks
Henry
- Tags:
- dircmp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-12-2005 05:40 AM
тАО10-12-2005 05:40 AM
Re: To pass comments on a script
I know it will take more scripting but it may be easier for you to create your list files so they have the relative path name as part of the file name
Find . -exec ls -ld {} \; > listing.out
Then write your own difference scanner using grep
Cat listing.out | while read LINE
Do
FILE=$(echo $LINE | awk '{print $NF}')
OLD_LINE=$(grep $FILE oldlist.out)
If [ $LINE = $OLD_LINE]
Then
#the file has not changed
elseif [ $OLD_LINE = "" ]
then
# $FILE is new or was not in the old listing
else
#something about the file is different
#you can write something to parse it and find out exactly what
fi
of course then you will have to run through the old list file and see if there are any files in it that are not in the new listing to check for deleted files.
I think that is what I would do instead of trying to write something to interpret the diff out put. Its up to you though
H
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-12-2005 06:30 AM
тАО10-12-2005 06:30 AM
Re: To pass comments on a script
Howard has you grep the oldlisting for the line, but that will not work if you have files with extensions of another files name (e.g. files fs and fs1 .. grep "fs" would find fs1) .... sooo I'll change that to awk.
find . -exec ls -ld {} \; > listing.out
Then write your own difference scanner using grep
cat listing.out | while read LINE
do
FILE=$(echo $LINE | awk '{print $NF}')
touch myfile
rm myfile
echo "XYZZY" $FILE > myfile
cat oldlist.out>>myfile
OLD_LINE=$(awk '/XYZZY/{damatch=$2;next;}if(damatch==$NF){print $0}' myfile)
if [ $LINE = $OLD_LINE]
then
#the file has not changed
elseif [ $OLD_LINE = "" ]
then
# $FILE is new or was not in the old listing
else
#something about the file is different
#you can write something to parse it and #find out exactly what
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-12-2005 09:21 AM
тАО10-12-2005 09:21 AM
Re: To pass comments on a script
I was going to leave the process of debugging and case testing to him, and then that wonderful thrill of getting the thing to finally work correctly.
But thanks for pointing out that it won't run correctly as written.
Henry, the script piece I wrote will not work as written. It's just a suggested guideline for you. If you want me to actually write the script for you please send a very large check to├в ┬ж..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-12-2005 02:42 PM
тАО10-12-2005 02:42 PM
Re: To pass comments on a script
Henry, here is a starting point... in perl.
I just could not get past the ugly, hardcoded shell data manipulations.
It just does MODE and SIZE. You do the rest!
Sample output:
$ perl x.p
Y day File Name 10112005.lst
T Day file Name 10122005.lst
10112005.lst Size Change
ps.tmp DELETED
tux.p Mode Change
x.p Size Change
10122005.lst CREATED
Script:
$ cat x.p
#
# Format and print file names (turn into subroutine?)
#
@t=localtime(time()-86400);
$yfile = sprintf ("%d%02d%04d.lst",1+@t[4],@t[3],1900+@t[5]);
@t=localtime;
$tfile = sprintf ("%d%02d%04d.lst",1+@t[4],@t[3],1900+@t[5]);
print "Y day File Name $yfile\nT Day file Name $tfile\n";
#
# Get listing for today
#
system ("ls -ltr . > $tfile");
#
# loop through result from diff, remembering some attributes for each file name.
# Hopefully file names are unique.
# Stach attribute in "T" or "Y" array based on > pr <
#
foreach (`diff $tfile $yfile`) {
($left_right, $mode, $links, $own, $group, $size, $d1, $d2, $t, $name) =split;
next unless $name;
$date = "$d1 $d2 $t";
if ($left_right eq '<') { $tmode{$name}=$mode, $tsize{$name}=$size };
if ($left_right eq '>') { $ymode{$name}=$mode, $ysize{$name}=$size };
}
#
# Walk over yesterdays names, comparing attributes.
# Delete todays files attribute when processed.
#
foreach $name (sort keys %ymode) {
$line = $name;
$line .= " Mode Change" if ($tmode{$name} ne $ymode{$name});
$line .= " Size Change" if ($tsize{$name} ne $ysize{$name});
$line = "$name DELETED" unless defined $tmode{$name};
print "$line\n";
delete $tmode{$name};
}
#
# Any remaining todays file is newly created
#
foreach $name (sort keys %tmode) {
print "$name CREATED\n";
}
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-12-2005 07:53 PM
тАО10-12-2005 07:53 PM
Re: To pass comments on a script
# diff /test.log1 /test.log2 | grep -v '[0-9]*c[0-9]'
< -rw-rw-rw- 1 root sys 33 Sep 21 00:08 ./tmpfile
---
> -rw-rw-rw- 1 muthu sys 33 Sep 21 00:08 ./tmpfile
Here, owner name is changed.
You can try as,
cd
find . -type f > /tmp/log${today}.log
diff /tmp/log${today}.log /tmp/log${yday}.log | grep -v '[0-9]*c[0-9]' > result.chg
You can use my script there in,
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=961895
It will not use more calculations.
hth.