Register
It is currently Tue Sep 23, 2014 10:20 am

ECHO command not print on my script


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Sun Apr 15, 2012 9:24 pm   

Joined: Sun Apr 15, 2012 9:18 pm
Posts: 1
Hello,

I'm newbie on shell scripting. I'm writing very basic shell script see below

Code:
#!/bin/bash
#
#Ognoo=$(date)

# this is path of archive
mobile=/storage/shared/mobile
medium=/storage/shared/medium

# total size of files thats equal and older than 15 days
mosize=$(find $mobile -type f -exec ls -l {} \; | awk '{ s+=$5 } END { print s }')
mesize=$(find $medium -type f -exec ls -l {} \; | awk '{ s+=$5 } END { print s }')

# file count
mocount=$(find $mobile -type f  | wc -l)
mecount=$(find $medium -type f  | wc -l)

# mail related
# ipaddr=$(/sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}')

if [[ $mecount -gt 0 || $mocount -gt 0 ]]; then

        find $medium -type f  -exec rm {} \;
        find $mobile -type f  -exec rm {} \;

        if [[ $mocount -eq 0 && $mecount -eq 0 ]]; then

                echo "$(date) Successfully deleted" >> archive_deleter.log
                echo "$(date) MEDIUMi size: $mesize number of files: $mecount MOBILE size: $mosize number of files: $mocount tus bur ustgalaa." | mail -s "Server: $ipaddr archive removed successfully" tseveendorj.o@localhost
        else
                echo "$(date) Error: file(s) => 15 days still has in these directories" >> archive_deleter.log
        fi
else
        echo "$(date) There has no files equal and older than 15 days" >> archive_deleter.log
fi


this file contains many echo commands but does not print on Terminal of Ubuntu. And also it did not send email. when I cat my postfix log from /var/log/mail.log no record. How do I fix this ?


Top
 Profile  
 PostPosted: Sun Apr 15, 2012 10:48 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 548
hi,

$m?count are not updated, so they keep the value they had when script enters the first `if'.

btw, using `ls' is rarely a good idea, instead I suggest you use find's -printf option.

<command> | grep | cut | awk is not the best way: use a single awk statement (awk can match regex, and cut by itself, at least).


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP