+ Reply to Thread
Results 1 to 6 of 6

Thread: Help with bash script

  1. #1
      Advisor tolstoy
    Join Date
    May 2001
    Posts
    564

    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
      Advisor tolstoy
    Join Date
    May 2001
    Posts
    564

    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
      Advisor redhead redhead's Avatar
    Join Date
    Jun 2001
    Location
    Copenhagen, Denmark
    Posts
    756

    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
      Advisor tolstoy
    Join Date
    May 2001
    Posts
    564

    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
      Advisor redhead redhead's Avatar
    Join Date
    Jun 2001
    Location
    Copenhagen, Denmark
    Posts
    756

    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     = "[email protected]"
    SUPPORT   = "[email protected]"
    PHONE    = ""
    #
    # end of example warnquota.conf file
    #
    redhead@odin:~# su -c "cat /etc/quota.conf "
    Password:
    redhead@odin:~#

  6. #6
      Advisor tolstoy
    Join Date
    May 2001
    Posts
    564

    Re: Help with bash script

    Thanks.

+ Reply to Thread

Similar Threads

  1. SSH and bash script
    By vwgtiturbo in forum Programming
    Replies: 7
    Last Post: 12-25-2008, 05:40 AM
  2. Bash script
    By linuxuser in forum Programming
    Replies: 1
    Last Post: 09-01-2005, 04:21 PM
  3. Bash Script question….
    By gfunkmonk in forum Programming
    Replies: 6
    Last Post: 08-26-2002, 10:47 PM
  4. Replies: 5
    Last Post: 04-18-2002, 11:56 AM
  5. bash script to delete files
    By cloverm in forum Programming
    Replies: 16
    Last Post: 02-24-2002, 08:03 PM

Bookmarks

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