- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- shell 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
Forums
Discussions
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
09-01-2005 03:15 PM
09-01-2005 03:15 PM
In my backup directory (Linux Os) everyday one file will be created automatically by cron. I want to check the size of the file which is created today with yesterdays file. if todays file is smaller than y'days file then delete todays file and send mail to specific user to report the problem.
please guide me how to write a shell script with above specification.
Your help will be highly appreciated.
Thanks in advance.
ajay.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2005 05:30 PM
09-01-2005 05:30 PM
Re: shell script!
############################
yest_file=/home/temp/fil1
todays_file=/home/temp/file2
if [ -f
then
fsize_td=`/usr/sbin/du -sk
fi
if [ -f
then
fsize_yest=`/usr/sbin/du -sk
fi
if [ $fsize_td -lt $fsize_yest ]
then
/bin/mail -s "`date` Today's file having problem....."
fi
##########
Hope this hint will help.
Cheers,
Rajesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2005 05:53 PM
09-01-2005 05:53 PM
Re: shell script!
You can do this task like that ,
suppose your backup directory is /home/backup
#########################################
#!/usr/bin/bash
cd /home/backup
ls -l file.today | awk '{print $5}' > today
ls -l file.yest | awk '{print $5}' > yest
TODAY=`cat today` ; YEST=`cat yest`
if [ $TODAY < $YEST ]
then
echo " Todays file is smaller in size than yesterdays "
echo "Deleting todays file ..."
rm -i file.today
# Sending email..
echo "Sending email to the Administrator.."
echo " Alert! Todays backup file is smaller than yesterdays !" | mailx -s "Alert! Backup file smaller than yesterday" ajay@domain.com
echo "Email sent .."
# Removing temp fiel..
rm today ; rm yest
else
echo " Todays backup file file.today is not smaller than yesterdays file"
fi
############################################
Note: file.today and file.yest has to be replace with your file name in backup directory , that generates with yesterday and today.
Hope this will help you ,
Cheers,
Raj.D.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2005 06:05 PM
09-01-2005 06:05 PM
Re: shell script!
Also you can add [ -f filename ] , will check for the exisitance of the file.
So the script will look like this:
----------------------------------------
#########################################
#!/bin/bash
cd /home/backup
# Checking file existance.
if [ -f file.today ]
then
echo " [OK]: file(todays) exists."
else
echo " todays file doesnot exists "
fi
# #
if [ -f file.yest ]
then
echo " [OK]: file(yesterdays) exists."
else
echo " Yesterdays file doesnot exists "
fi
########File check done..################
#########################################
# Comparing file size .......
#########################################
ls -l file.today | awk '{print $5}' > today
ls -l file.yest | awk '{print $5}' > yest
TODAY=`cat today` ; YEST=`cat yest`
if [ $TODAY < $YEST ]
then
echo " Todays file is smaller in size than yesterdays "
echo "Deleting todays file ..."
rm -i file.today
# Sending email..
echo "Sending email to the Administrator.."
echo " Alert! Todays backup file is smaller than yesterdays !" | mailx -s "Alert! Backup file smaller than yesterday" ajay@domain.com
echo "Email sent .."
# Removing temp fiel..
rm today ; rm yest
else
echo " Todays backup file file.today is not smaller than yesterdays file"
fi
############################################
you can try it and let us know ..
Cheers,
Raj.D
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2005 11:04 PM
09-01-2005 11:04 PM
Solution#!/bin/bash
TFILE="file_$(date +'%d_%m_%y')"
YFILE="file_$(date -d "yesterday" +'%d_%m_%y')"
TSIZE=$(ls -l $file | cut -d" " -f5)
YSIZE=$(ls -l $file | cut -d" " -f5)
USER=$(ls -l $file | cut -d" " -f2)
if [[ ${TSIZE} -lt ${YSIZE} ]]
then
rm -f ${TFILE}
echo "Problem with today's mail. ${TFILE}" | mail $USER@domain
fi
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2005 02:53 AM
09-05-2005 02:53 AM
Re: shell script!
Any update on the script problem. Does the above scripts working. pls update.
Cheers ,
Raj.D
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2005 04:53 PM
09-06-2005 04:53 PM
Re: shell script!
thank you very much that you all helped me. i taken small part in every script you provided and customised as per my requirement.
file names what i am using in this script are dynamic(everyday changes during the date in its name).those files created by another backup script.sorry i dint mension it in my question.
so i feel Muttukumar script a bit easy. but (cut -d" " -f5) that is pointing to diff field. (cut -d" " -f13) is getting the size of the file field.
this is my script which i costomized with the help of you all.
#!/bin/bash
TFILE="dbname_$(date +20'%y-%m-%d.%A').sql.gz";
YFILE="dbname_$(date -d "yesterday" +'20%y-%m-%d.%A').sql.gz";
if [ -f $TFILE ] && [ -f $YFILE ]
then
TSIZE=$(ls -l $TFILE | awk '{print $5}');
YSIZE=$(ls -l $YFILE | awk '{print $5}');
if [[ ${TSIZE} -lt ${YSIZE} ]]
then
rm -rf ${TFILE};
echo "Problem with todays backedup file name ${TFILE} with ${TSIZE} byte size. YDay file size is $YSIZE" byte | mail -s "Alert" ajay@domain.com;
fi
else
echo "file/files missing in $HOSTNAME" | mail -s "Red Alert" ajay@domain.com;
fi
Once again thank you very much. and expecting the same in future.
Regards,
ajay