- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: diff - scripts
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
Forums
Discussions
Discussions
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
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
05-23-2007 02:59 AM
05-23-2007 02:59 AM
Please I need a help.
I'm using HPUX 11
I have two files called 05_05_2007.txt and 06_05_2007.txt in the directory /tmp
-rw-rw-rw- 1 F0104582 fnusr 22 May 23 10:56 05_05_2007.txt
-rw-rw-rw- 1 F0104582 fnusr 59 May 23 10:57 06_05_2007.txt
I need to do a script that to compare theses two files.
BUT everday theses files will change his names because I create according with the currente date
Today I need to compare the file of today with the file of yesterday and tomorrow the same thing.
In other words, everyday I need to compare the actual file with the file of the day before.
For exampple:
#:/diff 05_05_2007.txt 06_05_2007.txt > a.txt
I don't know how can I get theses files in the directory.
#:/diff $A $B > a.txt
How can I do it automatically? I will put this script in the crontab.
Please could someone give me a help?
Thanks a lot!
clefeitosa
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2007 03:18 AM
05-23-2007 03:18 AM
SolutionThe rest is then trivially simple.
----------------------------------------
#!/usr/bin/sh
export PATH=${PATH}:/usr/local/bin
TODAY="$(caljd.sh -e -S "_" $(caljd.sh)).txt"
YESTERDAY="$(caljd.sh -e -S "_" $(caljd.sh -p 1)).txt"
echo "Today File = ${TODAY}"
echo "Yesterday File = ${YESTERDAY}"
---------------------------------------
Invoke as caljd.sh -u for full usage and many examples.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2007 04:35 AM
05-23-2007 04:35 AM
Re: diff - scripts
Thanks for your answer but I don't install something. This script is very good but I think that isn't necessary for me. I would like something simplier.
Anyway, thank you very much... I'm studying about it and if someone knows anything more, please...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2007 04:42 AM
05-23-2007 04:42 AM
Re: diff - scripts
# export TZ="GMT"
# date +%d_%m_%Y
23_05_2007
# export TZ="GMT+24"
# date +%d_%m_%Y
22_05_2007
# unset TZ
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2007 04:51 AM
05-23-2007 04:51 AM
Re: diff - scripts
ls -1 [0-3][0-9]_[01][0-9]_2[0-9][0-9][0-9].txt | sort -n -t'_' -k3 -k2 -k1 | tail -n 2 | xargs diff > a.txt
PCS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2007 05:10 AM
05-23-2007 05:10 AM
Re: diff - scripts
Since you didn't like caljd.sh (I assume you did a chmod 755 caljd.sh after you copied it) then this shell script which calls a Perl one-liner should work:
-----------------------------------------
#!/usr/bin/sh
TODAY=$(perl -e '($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time()); printf("%02d_%02d_%04d.txt\n",$mday,$mon + 1,$year + 1900)')
YESTERDAY=$(perl -e '($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time() - (86400 * 1)); printf("%02d_%02d_%04d.txt\n",$mday,$mon + 1,$year + 1900);')
echo "Today File = ${TODAY}"
echo "Yesterday File = ${YESTERDAY}"
-----------------------------------------
Now, caljd.sh (or the equivalent caljd.pl Perl version) is a big script but who cares? You only call it --- and if you start using it for date calculations of any kind, I'm pretty sure that you won't use anything else.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2007 05:13 AM
05-23-2007 05:13 AM
Re: diff - scripts
If you simply want today and yesterday returned in the format "dd_mm_yyyy":
# TODAY=`perl -MPOSIX -le 'print strftime "%d_%m_%Y",localtime'`
# YESTERDAY=`perl -MPOSIX -le 'print strftime "%d_%m_%Y",localtime(time-86400)'`
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2007 05:24 AM
05-23-2007 05:24 AM
Re: diff - scripts
diff `ls -t|head -2`
(Note that those are back-quotes. The ls will list with the most recent file first, and the head will give the first two.)
Andrew
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2007 06:59 AM
05-23-2007 06:59 AM
Re: diff - scripts
Thank you very much for all answers!!!
Was very useful!
I'll use Andrew's suggestion.
Best regards,
clefeitosa
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2007 07:00 AM
05-23-2007 07:00 AM
Re: diff - scripts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2007 05:13 PM
05-23-2007 05:13 PM
Re: diff - scripts
If you used the following you wouldn't have to say that:
$ diff $(ls -t|head -2)
>BUT everday theses files will change his names because I create according with the current date
If you have more complicated case where the files are changing, you could try setting symlinks to point to the last 2 files. Have a LAST link and a PREV link. When creating a new file, remove PREV, rename LAST to PREV and link the new name to LAST.
Note it would be better to create the files with YYYY_MM_DD.
A simple script using sed can be used to rename all of your existing files.