Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19
Help with bash script
Results 1 to 6 of 6

Thread: Help with bash script

Hybrid View

  1. #1

    Help with bash script

    Ok, to start with I'm not much of a programmer, so bare with me if this script is a bit sloppy and longer than it need be. The script is supposed to check a users quota usage on given partitions and then send a warning email if they are nearing their limit.

    However, when I test the script, i get the following error
    Code:
    [ : : integer expression expected
    I'm pretty sure the error is with the if/then comparison [ "$quota_usage" -gt $QUOTA_LIMIT ], but what's wrong, I don't know. Could it be that $quota_usage is a string and not an integer? If so, is it possible to cast $quota_usage as an integer, or is this asking too much of bash? I'm sure I'm overlooking something very simple, but like I said, I'm not much of a coder.

    Here's the full script
    Code:
    #!/bin/bash
    
    QUOTA_LIMIT=8960
    MAIL_BODY="/etc/QuotaMail.txt"
    MAIL_DIR="/var/spool/mail/"
    WARNING_SUBJECT="WARNING: YOUR MAIL ACCOUNT IS REACHING ITS QUOTA LIMIT"
    PARTITIONS="/dev/ida/c0d0p5 /dev/ida/c0d0p6"
    
    awk -F: '{ print $1 }' /etc/passwd > /tmp/usernames
    {
       while read username; do
          for i in $PARTITIONS; do
             block_usage=`quota $username | grep $i | awk -F' ' '{ print $2 }' | sed s/*//`
             if [ $block_usage -gt $QUOTA_LIMIT ]; then
                has_exceeded_quota_limit="yes"
             else
                has_exceeded_quota_limit="no"
             fi
          done
          if ! grep "$WARNING_SUBJECT" "$MAIL_DIR"$username &&
             [ "$has_exceeded_quota_limit" = "yes" ]; then
                cat $MAIL_BODY | mail -s "$WARNING_SUBJECT" $username
          fi
       done
    } < /tmp/usernames && rm /tmp/usernames

  2. #2

    Re: Help with bash script

    Ah, I figured it out. I needed:
    Code:
    declare -i block_usage
    So now on to another question. Could the above code been written better? Is anything in it excessive?

  3. #3
    Moderator
    Advisor
    redhead's Avatar
    Join Date
    Jun 2001
    Location
    Copenhagen, Denmark
    Posts
    811

    Re: Help with bash script

    Why not just use quotacheck ??
    You set everything in /etc/warnquota.conf, and have your /etc/cron.daily/warnquota
    :~# cat /etc/cron.daily/warnquota
    #!/bin/sh
    /usr/sbin/warnquota
    It handles everything for you, and its just a part of your normal quota package.. No need to make a manual scan of the file structure..
    (That is, if you are using quotas for the users)

  4. #4

    Re: Help with bash script

    Why not just use quotacheck ??
    You set everything in /etc/warnquota.conf, and have your /etc/cron.daily/warnquota
    It handles everything for you, and its just a part of your normal quota package.. No need to make a manual scan of the file structure..
    (That is, if you are using quotas for the users)
    See, I knew there was an easier way to do this. warnquota is on my system, but not warnquota.conf. Does anyone have any suggestions as to what its syntax should be?

  5. #5
    Moderator
    Advisor
    redhead's Avatar
    Join Date
    Jun 2001
    Location
    Copenhagen, Denmark
    Posts
    811

    Re: Help with bash script


    Does anyone have any suggest as to what it's syntax should be?
    To make this quick... And easy(tm)
    Code:
    redhead@odin:~# rpm -q quota
    quota-3.01pre9-3
    redhead@odin:~# cat /etc/warnquota.conf
    # this is an example warnquota.conf
    #
    ; ; and # type comments are allowed
    # and even blank lines
    
    MAIL_CMD = "/usr/sbin/sendmail -t"
    FROM     = "root@localhost"
    SUBJECT   = Disk Quota usage on system
    CC_TO     = "bofh@redhead.dk"
    SUPPORT   = "quota@redhead.dk"
    PHONE    = ""
    
    #
    # end of example warnquota.conf file
    #
    redhead@odin:~# su -c "cat /etc/quota.conf "
    Password:
    redhead@odin:~#

  6. #6

    Re: Help with bash script

    Thanks.

Similar Threads

  1. Help with bash script
    By woodson2 in forum Linux - Software, Applications & Programming
    Replies: 5
    Last Post: 12-30-2010, 07:19 PM
  2. SSH and bash script
    By vwgtiturbo in forum Programming
    Replies: 7
    Last Post: 12-25-2008, 05:40 AM
  3. Bash script problem
    By Schotty in forum Programming
    Replies: 1
    Last Post: 04-20-2007, 01:18 AM
  4. Bash script
    By linuxuser in forum Programming
    Replies: 1
    Last Post: 09-01-2005, 03:21 PM
  5. Bash script for sorting mp3's.
    By airhead in forum Programming
    Replies: 7
    Last Post: 02-24-2002, 07:09 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •