Solved

Shell Script with e-mail...

Posted on 2000-03-08
7
194 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
  • 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now