Results 1 to 2 of 2

Thread: Using Grep and regex to pull a value out of a string

  1. #1

    Using Grep and regex to pull a value out of a string

    Hi all

    I'm new to shell script and I want to write a script that checks to see how many of my virtual machines are running and if it is below the correct amount to send me an email

    the command i need to run is simply

    $ vmrun list

    this returns me

    Total Running VMs: 4

    so basically i want to write a script that says

    myvar = `vmrun list | grep [only get me the number, e.g. 4] | wc -l`

    if [ $myvar < 4 ] then
    email me a message at 'mymail@mail.com' saying 'not all vms are running'

    or even

    email me a message at 'mymail@mail.com' with the output from the command vmrun list

    If anyone could help me with the actual shell script then I'd be very happy

  2. #2
    Moderator
    Advisor
    redhead's Avatar
    Join Date
    Jun 2001
    Location
    Copenhagen, Denmark
    Posts
    811
    Awk will be better for this ie:
    Code:
    #!/bin/sh
    NUMBER=`vmrun list | awk '{print $NF}'`
    if [ $NUMBER le 3 ] ; then
      echo "Less than the desired 4 running" | mail -s "Stats from wmrun" mymail@mail.com
    else
      echo "equal or more than the desired 4 running" | mail -s "Stats from wmrun" mymail@mail.com
    fi
    Don't worry Ma'am. We're university students, - We know what We're doing.
    'Ruiat coelum, fiat voluntas tua.'
    Datalogi - en livsstil; Intet liv, ingen stil.

Similar Threads

  1. grep absolute path
    By svar in forum Linux - Software, Applications & Programming
    Replies: 1
    Last Post: 12-02-2010, 04:41 AM
  2. Using grep in my home directory
    By Clai2x in forum Linux - Software, Applications & Programming
    Replies: 0
    Last Post: 12-19-2007, 04:57 AM
  3. B&J, please don't pull yet another good flavor!!
    By Outlaw in forum General Chat
    Replies: 2
    Last Post: 04-22-2006, 04:54 PM
  4. What does 'locate network grep howto' do?
    By Smegma in forum Linux - Software, Applications & Programming
    Replies: 7
    Last Post: 03-28-2004, 04:16 AM
  5. finding a friggin tab with sed or grep
    By morphman in forum Linux - Software, Applications & Programming
    Replies: 13
    Last Post: 04-27-2002, 06:31 AM

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
  •