- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Shell script to run everyday using diff command
Operating System - Linux
1824635
Members
4228
Online
109672
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
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
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- 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-01-2005 12:14 PM
тАО10-01-2005 12:14 PM
Shell script to run everyday using diff command
Hi All
I am new bee to Shell scripting and HP-UX.
I am trying to write a script which should run everyday to Long list (ll in HPUX and ls -la in Solaris)all the files in all the directories except /tmp , /var directories and store in a new directory with title "Mondd" (like Sep30) .And it should also run the script nextday and capture the difference between previous day's longlist(ll) and currentday longlist (ll) [I think diff command in HPUX should help it out for Example "diff file1 file2 > file12"] and save it to new directory titled "today mondd".
I would appreciate if you guys could help me out on this.
Thanks
Henry
I am new bee to Shell scripting and HP-UX.
I am trying to write a script which should run everyday to Long list (ll in HPUX and ls -la in Solaris)all the files in all the directories except /tmp , /var directories and store in a new directory with title "Mondd" (like Sep30) .And it should also run the script nextday and capture the difference between previous day's longlist(ll) and currentday longlist (ll) [I think diff command in HPUX should help it out for Example "diff file1 file2 > file12"] and save it to new directory titled "today mondd".
I would appreciate if you guys could help me out on this.
Thanks
Henry
- Tags:
- diff
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-01-2005 02:40 PM
тАО10-01-2005 02:40 PM
Re: Shell script to run everyday using diff command
# DIRLIST variable contains the
# list of directories you want to scan
DIRLIST="/ /home /opt /usr /data"
# ASSIGN today's date to variable TODAY
TODAY=`date +%b%d`
# find what was yesterday's date and assign
# it to the variable YESTERDAY
YESTERDAY=`cat YESTERDAYname`
# scan the directories and build today's file
for DIR in $DIRLIST
do
ls -al $DIR >> $TODAY
done
# run the diff command and store the output
diff $TODAY $YESTERDAY > ${TODAY}-${YESTERDAY}
# optionally delete yesterday's file
rm $YESTERDAY
# change yesterday's file name for tomorrow
echo $TODAY > YESTERDAYname
on the first day, just run this portion to build the first day's file as you do not have anything to run the diff command on.
DIRLIST="/ /home /opt /usr /data"
TODAY=`date +%b%d`
for DIR in $DIRLIST
do
ls -al $DIR >> $TODAY
done
Also adjust the path of the output files to wherever you wish to store them, otherwise this code above will place them where you launch this code from, i.e., current directory.
Hope this helps
# list of directories you want to scan
DIRLIST="/ /home /opt /usr /data"
# ASSIGN today's date to variable TODAY
TODAY=`date +%b%d`
# find what was yesterday's date and assign
# it to the variable YESTERDAY
YESTERDAY=`cat YESTERDAYname`
# scan the directories and build today's file
for DIR in $DIRLIST
do
ls -al $DIR >> $TODAY
done
# run the diff command and store the output
diff $TODAY $YESTERDAY > ${TODAY}-${YESTERDAY}
# optionally delete yesterday's file
rm $YESTERDAY
# change yesterday's file name for tomorrow
echo $TODAY > YESTERDAYname
on the first day, just run this portion to build the first day's file as you do not have anything to run the diff command on.
DIRLIST="/ /home /opt /usr /data"
TODAY=`date +%b%d`
for DIR in $DIRLIST
do
ls -al $DIR >> $TODAY
done
Also adjust the path of the output files to wherever you wish to store them, otherwise this code above will place them where you launch this code from, i.e., current directory.
Hope this helps
________________________________
UNIX because I majored in cryptology...
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-02-2005 12:52 PM
тАО10-02-2005 12:52 PM
Re: Shell script to run everyday using diff command
#! /usr/bin/sh dt1=`date`
# year=`echo $dt1|cut -d" " -f6`
# month=`echo $dt1|cut -d" " -f2`
thisdate=`echo $dt1|cut -d" " -f3`
# fname=$month$thisdate$year.lst
# ls -R >$fname
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`
fname=$MONTH$thisdate$YEAR.lst
echo $fname
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 " $fname
ls -R >$fname
diff $fname $yfile >result.lst
Can you guys Please help me on how to improve on this.I would also like to aexlude /home & /Var
Please suggest how to improve it better
Thanks
Henry
# year=`echo $dt1|cut -d" " -f6`
# month=`echo $dt1|cut -d" " -f2`
thisdate=`echo $dt1|cut -d" " -f3`
# fname=$month$thisdate$year.lst
# ls -R >$fname
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`
fname=$MONTH$thisdate$YEAR.lst
echo $fname
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 " $fname
ls -R >$fname
diff $fname $yfile >result.lst
Can you guys Please help me on how to improve on this.I would also like to aexlude /home & /Var
Please suggest how to improve it better
Thanks
Henry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-02-2005 06:36 PM
тАО10-02-2005 06:36 PM
Re: Shell script to run everyday using diff command
You can use this script:
#!/bin/ksh
# diffscr.ksh
LOGFILE=/var/diff/$(date +'%b%d').log
# Prev. Date
OLDTZ=$TZ
TZ=$TZ+24
YESLOGFILE=/var/diff/$(date +'%b%d').log
TZ=$OLDTZ
# File & Directory Search - Add more if you want
for fdir `ls -l | grep -Ev 'var|tmp|home|total' | awk '{ print $NF }'`
do
find $fdir -type f -exec ls -l {} \+ >>$LOGFILE
done
if [ -f $LOGFILE && -f $YESLOGFILE ]
then
diff $LOGFILE $YESLOGFILE
fi
exit 0
# END
hth
#!/bin/ksh
# diffscr.ksh
LOGFILE=/var/diff/$(date +'%b%d').log
# Prev. Date
OLDTZ=$TZ
TZ=$TZ+24
YESLOGFILE=/var/diff/$(date +'%b%d').log
TZ=$OLDTZ
# File & Directory Search - Add more if you want
for fdir `ls -l | grep -Ev 'var|tmp|home|total' | awk '{ print $NF }'`
do
find $fdir -type f -exec ls -l {} \+ >>$LOGFILE
done
if [ -f $LOGFILE && -f $YESLOGFILE ]
then
diff $LOGFILE $YESLOGFILE
fi
exit 0
# END
hth
Easy to suggest when don't know about the problem!
- Tags:
- find
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Learn About
News and Events
Support
© Copyright 2025 Hewlett Packard Enterprise Development LP