<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: shell script! in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/shell-script/m-p/3617452#M19405</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;############################&lt;BR /&gt;yest_file=/home/temp/fil1&lt;BR /&gt;todays_file=/home/temp/file2&lt;BR /&gt;&lt;BR /&gt;if [ -f &lt;TODAYS_FILE&gt; ]&lt;BR /&gt;then&lt;BR /&gt;  fsize_td=`/usr/sbin/du -sk &lt;TODAYS_FILE&gt;|awk -F '{ print $1 }'`;&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;if [ -f &lt;YEST_FILE&gt; ]&lt;BR /&gt;then&lt;BR /&gt;  fsize_yest=`/usr/sbin/du -sk &lt;YEST_FILE&gt;|awk -F '{ print $1 }'`;&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;if [ $fsize_td -lt $fsize_yest ]&lt;BR /&gt;then&lt;BR /&gt;   /bin/mail -s "`date` Today's file having problem....." &lt;XYZ&gt;&lt;BR /&gt;fi&lt;BR /&gt;##########&lt;BR /&gt;&lt;BR /&gt;Hope this hint will help.&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;&lt;BR /&gt;Rajesh&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/XYZ&gt;&lt;/YEST_FILE&gt;&lt;/YEST_FILE&gt;&lt;/TODAYS_FILE&gt;&lt;/TODAYS_FILE&gt;</description>
    <pubDate>Fri, 02 Sep 2005 00:30:42 GMT</pubDate>
    <dc:creator>Rajesh SB</dc:creator>
    <dc:date>2005-09-02T00:30:42Z</dc:date>
    <item>
      <title>shell script!</title>
      <link>https://community.hpe.com/t5/operating-system-linux/shell-script/m-p/3617451#M19404</link>
      <description>Hi Everybody,&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;please guide me how to write a shell script with above specification.&lt;BR /&gt;&lt;BR /&gt;Your help will be highly appreciated.&lt;BR /&gt;&lt;BR /&gt;Thanks in advance.&lt;BR /&gt;&lt;BR /&gt;ajay.&lt;BR /&gt;</description>
      <pubDate>Thu, 01 Sep 2005 22:15:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/shell-script/m-p/3617451#M19404</guid>
      <dc:creator>ajay_25</dc:creator>
      <dc:date>2005-09-01T22:15:38Z</dc:date>
    </item>
    <item>
      <title>Re: shell script!</title>
      <link>https://community.hpe.com/t5/operating-system-linux/shell-script/m-p/3617452#M19405</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;############################&lt;BR /&gt;yest_file=/home/temp/fil1&lt;BR /&gt;todays_file=/home/temp/file2&lt;BR /&gt;&lt;BR /&gt;if [ -f &lt;TODAYS_FILE&gt; ]&lt;BR /&gt;then&lt;BR /&gt;  fsize_td=`/usr/sbin/du -sk &lt;TODAYS_FILE&gt;|awk -F '{ print $1 }'`;&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;if [ -f &lt;YEST_FILE&gt; ]&lt;BR /&gt;then&lt;BR /&gt;  fsize_yest=`/usr/sbin/du -sk &lt;YEST_FILE&gt;|awk -F '{ print $1 }'`;&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;if [ $fsize_td -lt $fsize_yest ]&lt;BR /&gt;then&lt;BR /&gt;   /bin/mail -s "`date` Today's file having problem....." &lt;XYZ&gt;&lt;BR /&gt;fi&lt;BR /&gt;##########&lt;BR /&gt;&lt;BR /&gt;Hope this hint will help.&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;&lt;BR /&gt;Rajesh&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/XYZ&gt;&lt;/YEST_FILE&gt;&lt;/YEST_FILE&gt;&lt;/TODAYS_FILE&gt;&lt;/TODAYS_FILE&gt;</description>
      <pubDate>Fri, 02 Sep 2005 00:30:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/shell-script/m-p/3617452#M19405</guid>
      <dc:creator>Rajesh SB</dc:creator>
      <dc:date>2005-09-02T00:30:42Z</dc:date>
    </item>
    <item>
      <title>Re: shell script!</title>
      <link>https://community.hpe.com/t5/operating-system-linux/shell-script/m-p/3617453#M19406</link>
      <description>Hi Ajay ,&lt;BR /&gt;&lt;BR /&gt;You can do this task like that ,&lt;BR /&gt;&lt;BR /&gt;suppose your backup directory is /home/backup&lt;BR /&gt;&lt;BR /&gt;#########################################&lt;BR /&gt;#!/usr/bin/bash&lt;BR /&gt;cd /home/backup&lt;BR /&gt;ls -l file.today | awk '{print $5}' &amp;gt; today&lt;BR /&gt;ls -l file.yest  | awk '{print $5}' &amp;gt; yest&lt;BR /&gt;TODAY=`cat today` ; YEST=`cat yest`&lt;BR /&gt;if [ $TODAY &amp;lt; $YEST ]&lt;BR /&gt;then &lt;BR /&gt;echo " Todays file is smaller in size than yesterdays "&lt;BR /&gt;echo "Deleting todays file ..."&lt;BR /&gt;rm -i file.today&lt;BR /&gt;# Sending email..&lt;BR /&gt;echo "Sending email to the Administrator.."&lt;BR /&gt;echo " Alert! Todays backup file is smaller than yesterdays !" | mailx -s "Alert! Backup file smaller than yesterday" ajay@domain.com &lt;BR /&gt;&lt;BR /&gt;echo "Email sent .."&lt;BR /&gt;# Removing temp fiel..&lt;BR /&gt;rm today  ; rm yest&lt;BR /&gt;&lt;BR /&gt;else &lt;BR /&gt;echo " Todays backup file file.today is not smaller than yesterdays file"&lt;BR /&gt;fi&lt;BR /&gt;############################################&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Note: file.today and file.yest has to be replace with your file name in backup directory , that generates with yesterday and today.&lt;BR /&gt;&lt;BR /&gt;Hope this will help you ,&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Raj.D.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 02 Sep 2005 00:53:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/shell-script/m-p/3617453#M19406</guid>
      <dc:creator>Raj D.</dc:creator>
      <dc:date>2005-09-02T00:53:08Z</dc:date>
    </item>
    <item>
      <title>Re: shell script!</title>
      <link>https://community.hpe.com/t5/operating-system-linux/shell-script/m-p/3617454#M19407</link>
      <description>Ajay,&lt;BR /&gt;&lt;BR /&gt;Also you can add [ -f filename ] , will check for the exisitance of the file.&lt;BR /&gt;&lt;BR /&gt;So the script will look like this:&lt;BR /&gt;----------------------------------------&lt;BR /&gt;&lt;BR /&gt;#########################################&lt;BR /&gt;#!/bin/bash  &lt;BR /&gt;cd /home/backup&lt;BR /&gt;# Checking file existance.&lt;BR /&gt;if [ -f file.today ]&lt;BR /&gt;then &lt;BR /&gt;echo " [OK]: file(todays) exists."&lt;BR /&gt;else &lt;BR /&gt;echo " todays  file doesnot exists "&lt;BR /&gt;fi&lt;BR /&gt;# # &lt;BR /&gt;if [ -f file.yest ]&lt;BR /&gt;then &lt;BR /&gt;echo " [OK]: file(yesterdays) exists."&lt;BR /&gt;else &lt;BR /&gt;echo " Yesterdays file doesnot exists "&lt;BR /&gt;fi&lt;BR /&gt;########File check done..################&lt;BR /&gt;&lt;BR /&gt;#########################################&lt;BR /&gt;# Comparing file size .......&lt;BR /&gt;#########################################&lt;BR /&gt;&lt;BR /&gt;ls -l file.today | awk '{print $5}' &amp;gt; today&lt;BR /&gt;ls -l file.yest | awk '{print $5}' &amp;gt; yest&lt;BR /&gt;TODAY=`cat today` ; YEST=`cat yest`&lt;BR /&gt;if [ $TODAY &amp;lt; $YEST ]&lt;BR /&gt;then &lt;BR /&gt;echo " Todays file is smaller in size than yesterdays "&lt;BR /&gt;echo "Deleting todays file ..."&lt;BR /&gt;rm -i file.today&lt;BR /&gt;# Sending email..&lt;BR /&gt;echo "Sending email to the Administrator.."&lt;BR /&gt;echo " Alert! Todays backup file is smaller than yesterdays !" | mailx -s "Alert! Backup file smaller than yesterday" ajay@domain.com &lt;BR /&gt;&lt;BR /&gt;echo "Email sent .."&lt;BR /&gt;# Removing temp fiel..&lt;BR /&gt;rm today ; rm yest&lt;BR /&gt;&lt;BR /&gt;else &lt;BR /&gt;echo " Todays backup file file.today is not smaller than yesterdays file"&lt;BR /&gt;fi&lt;BR /&gt;############################################&lt;BR /&gt;&lt;BR /&gt;you can  try it and let us know ..&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Raj.D&lt;BR /&gt;</description>
      <pubDate>Fri, 02 Sep 2005 01:05:59 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/shell-script/m-p/3617454#M19407</guid>
      <dc:creator>Raj D.</dc:creator>
      <dc:date>2005-09-02T01:05:59Z</dc:date>
    </item>
    <item>
      <title>Re: shell script!</title>
      <link>https://community.hpe.com/t5/operating-system-linux/shell-script/m-p/3617455#M19408</link>
      <description>You can try as,&lt;BR /&gt;&lt;BR /&gt;#!/bin/bash&lt;BR /&gt;&lt;BR /&gt;TFILE="file_$(date +'%d_%m_%y')"&lt;BR /&gt;YFILE="file_$(date -d "yesterday" +'%d_%m_%y')"&lt;BR /&gt;&lt;BR /&gt;TSIZE=$(ls -l $file | cut -d" " -f5)&lt;BR /&gt;YSIZE=$(ls -l $file | cut -d" " -f5)&lt;BR /&gt;USER=$(ls -l $file | cut -d" " -f2)&lt;BR /&gt;&lt;BR /&gt;if [[ ${TSIZE} -lt ${YSIZE} ]]&lt;BR /&gt;then&lt;BR /&gt;   rm -f ${TFILE}&lt;BR /&gt;   echo "Problem with today's mail. ${TFILE}" | mail $USER@domain&lt;BR /&gt;&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;hth.</description>
      <pubDate>Fri, 02 Sep 2005 06:04:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/shell-script/m-p/3617455#M19408</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2005-09-02T06:04:51Z</dc:date>
    </item>
    <item>
      <title>Re: shell script!</title>
      <link>https://community.hpe.com/t5/operating-system-linux/shell-script/m-p/3617456#M19409</link>
      <description>Hi Ajay ,&lt;BR /&gt;&lt;BR /&gt;Any update on the script problem. Does the above scripts working. pls update.&lt;BR /&gt;&lt;BR /&gt;Cheers ,&lt;BR /&gt;Raj.D&lt;BR /&gt;</description>
      <pubDate>Mon, 05 Sep 2005 09:53:18 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/shell-script/m-p/3617456#M19409</guid>
      <dc:creator>Raj D.</dc:creator>
      <dc:date>2005-09-05T09:53:18Z</dc:date>
    </item>
    <item>
      <title>Re: shell script!</title>
      <link>https://community.hpe.com/t5/operating-system-linux/shell-script/m-p/3617457#M19410</link>
      <description>hi guys,&lt;BR /&gt;&lt;BR /&gt;thank you very much that you all helped me. i taken small part in every script you provided and customised as per my requirement.&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;this is my script which i costomized with the help of you all.&lt;BR /&gt;&lt;BR /&gt;#!/bin/bash&lt;BR /&gt;TFILE="dbname_$(date +20'%y-%m-%d.%A').sql.gz";&lt;BR /&gt;YFILE="dbname_$(date -d "yesterday" +'20%y-%m-%d.%A').sql.gz";&lt;BR /&gt;if [ -f $TFILE ] &amp;amp;&amp;amp; [ -f $YFILE ]&lt;BR /&gt;then&lt;BR /&gt;        TSIZE=$(ls -l $TFILE | awk '{print $5}');&lt;BR /&gt;        YSIZE=$(ls -l $YFILE | awk '{print $5}');&lt;BR /&gt;                if [[ ${TSIZE} -lt ${YSIZE} ]]&lt;BR /&gt;                   then&lt;BR /&gt;                   rm -rf ${TFILE};&lt;BR /&gt;                echo "Problem with todays backedup file name ${TFILE} with ${TSIZE} byte size. YDay file size is  $YSIZE" byte | mail -s "Alert" ajay@domain.com;&lt;BR /&gt;fi&lt;BR /&gt;else&lt;BR /&gt;echo "file/files missing in $HOSTNAME" | mail -s "Red Alert" ajay@domain.com;&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Once again thank you very much. and expecting the same in future.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;ajay</description>
      <pubDate>Tue, 06 Sep 2005 23:53:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/shell-script/m-p/3617457#M19410</guid>
      <dc:creator>ajay_25</dc:creator>
      <dc:date>2005-09-06T23:53:37Z</dc:date>
    </item>
  </channel>
</rss>

