Solved

Shell Script with e-mail...

Posted on 2000-03-08
7
199 Views
Last Modified: 2011-09-20
I'm new to shell scripting, so please bear with me.  All that I want to do is cat a file that is known to either contain OK or FAIL, and if FAIL read a line from another file (grep for DEAD on that), and then (still if FAIL) take this second file's line and e-mail it.

I must assume that this would be "fairly" straightforward to someone who knows shell scripting.  Thanks!
0
Comment
Question by:Nietzsche
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 3

Expert Comment

by:jyu_88
ID: 2598997
assume file1 and file2, in a regular unix, linux, enviromenta

----cut--------cut----------
# /bin/sh

# backtick here, not single quote
status=`cat file1`

if [ "EMPTY$status" = "EMPTY" ]
then
    echo "nothing in file1????"
    exit 1
fi

if [ ${status} = "FAIL" ]
then
  grep "DEAD" file2 | mail -s "line from file2 when FAIL in file1" 2>/dev/null
fi
exit 0
------cut---cut-----
0
 

Author Comment

by:Nietzsche
ID: 2601919
When I run this (named runthis), I get the following:

../runthis:[EMPTYcat file1: command not found

../runthis:[cat: command not found

Any suggestions?
0
 

Author Comment

by:Nietzsche
ID: 2601926
..that was with no whitespace between the brackets and their contents ... if I put a space there, then I get
../runthis: [: too many arguments.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Accepted Solution

by:
jyu_88 earned 75 total points
ID: 2605444
# backtick here, not single quote
status=`cat file1`

are you sure you have backtick not single quote there?   FYI, backtick is the one sharing the same key with ~.

I've run the exact program on my Linux box without problem. So, I don't expect problem. Ruh, sorry, the first line should read like
#! /bin/sh
instead of
# /bin/sh
0
 
LVL 5

Expert Comment

by:ecw
ID: 2618647
grep -q FAIL file1 && grep DEAD file2 | mail -s "DEAD in file2" nietzsche
0
 

Author Comment

by:Nietzsche
ID: 2620690
Adjusted points from 50 to 75
0
 

Author Comment

by:Nietzsche
ID: 2620691
EXCELLENT!  As you said before, the "`" is indeed a backtick.  It's running beautifully - I'm using it to cat out /dev/rd/current_status and report back to me if any RAID drive shows up as "DEAD" - like: /dev/sda2  DEAD
Thanks for your help and patience!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question