- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Shell script to run everyday with Exclusion Me...
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
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-10-2005 02:16 AM
тАО10-10-2005 02:16 AM
Shell script to run everyday with Exclusion Mechanism
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".
Now I want to Add a mechanism for excluding files/directories/file systems from the report if they are known to change as part of regular operation of the system.Rightnow I do not what all the directories and files that are to be excluded so now I am looking to design the script with this capability of excluding some directories/files.
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/tt/tt2 >$tfile
diff $tfile $yfile >result.chg
I would appreciate if you guys could help me out on this.
Thanks
Henry
- Tags:
- dircmp
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-10-2005 02:58 AM
тАО10-10-2005 02:58 AM
Re: Shell script to run everyday with Exclusion Mechanism
I'd consider letting 'find' drive your principal 'ls' so that you can leverage directory selection and perhaps some basic filename selection or exclusion. For instance:
# find /etc/rc.config.d /sbin -type f ! -name "net*" -a ! -name "vg*" | xargs ls -l > /tmp/results
You could also use simple, stacked 'sed' commands to exclude other candidates before you 'diff' the two days files. For example:
# sed -e '/clean/d' -e '/set_parms/d' ...
If you like, the later specifications can be self-contained in a script that you pipe the output of the driving 'find' into, thereby creating the "results" to 'diff'.
Regards!
...JRF...
- Tags:
- find
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-10-2005 04:37 AM
тАО10-10-2005 04:37 AM
Re: Shell script to run everyday with Exclusion Mechanism
cheers!
- Tags:
- -prune
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-10-2005 06:43 AM
тАО10-10-2005 06:43 AM
Re: Shell script to run everyday with Exclusion Mechanism
so can I use the
# find / -a ! -name "vg*" | xargs ls -l > /tmp/results
instead of ls -ltR
I have a doubt will
find / -a! name " /dev/ "
will exclude that whole directory and all its sub-directories & files.
Thanks
Henry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-10-2005 06:53 AM
тАО10-10-2005 06:53 AM
Re: Shell script to run everyday with Exclusion Mechanism
Example-
find / ! \( -name "vg*" -a -path "/dev/*" \) | xargs ls -l > /tmp/results
Note the use of "path" for /dev/*.
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-10-2005 09:32 AM
тАО10-10-2005 09:32 AM
Re: Shell script to run everyday with Exclusion Mechanism
How do I exclude a particular directory
or a particular file using the find command
I tried the following command to delete a file ytre.txt located at /dev/first/ytre.txt
find /dev/first !\(-name "ytre" -a path /dev/first \)|xargs ls -l
But it didn't work
Please let me know the syntax of excluding particular directory/file using the find command
your help is appreciated.
Thanks
Henry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-10-2005 10:20 AM
тАО10-10-2005 10:20 AM
Re: Shell script to run everyday with Exclusion Mechanism
example-
find / ! \( -name "*yte*" -path "/dev/vg01/*" \) -print
This will ignore any files that have "yte" as part of their name or has a path that starts with "/dev/vg01".
Do not use -a in this case since "!" is a negative it reverses the sense of what's in the parenthesis.
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-11-2005 01:29 AM
тАО10-11-2005 01:29 AM
Re: Shell script to run everyday with Exclusion Mechanism
Another approach might be to create a list of directories that you DO want to list. Create this list in another file. Then your script can read this file and loop through that list doing your ls -l command.
In this way, once your script logic is set, you don't have to change it. You just add or remove directories from your 'directory file'.
Cheers,
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-11-2005 05:28 AM
тАО10-11-2005 05:28 AM
Re: Shell script to run everyday with Exclusion Mechanism
Thanks James,Sandman,Rod & Mark
Mark,
I have question for you,
can you suggest a mechanism or an approach of how to fit in that file that contains the list of directories that HAVE to be included into my above posted script.
Thanks
Henry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-11-2005 05:55 AM
тАО10-11-2005 05:55 AM
Re: Shell script to run everyday with Exclusion Mechanism
You can do something like this:
...
while read PATHNAME
do
find ${PATHNMME} ...
done < your_file_of_directories
Rodneys' suggestion to use the '-path' option to exclude directories is a good one, but it may not be entirely portable. AIX doesn't allow it and I don't know about Solaris.
You can use '-prune' as an alternative. It operates OK if you first change directories before your 'find' and thus do something like:
# cd somedirectory
# find . -name NOTTHIS -prune -o -print
The above would print all files in "somedirectory" except those in the subdirectory "NOTTHIS".
I'm not fully sure what you ultimate goal is here. If you are trying to track changes in files, then you need to potentially look at more than just file timestamps, sizes and permissions. Checksum changes would be the next level to track.
If you are really going down that route, a perl program would be a good answer. Perl has a builtin find() function. You could couple its use with the stat() function to get the same information 'ls' returns. Tracking changes could be done with hashes containing the data you want to monitor.
Regards!
...JRF...