?
Solved

Shell Script with e-mail...

Posted on 2000-03-08
7
Medium Priority
?
201 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
Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

 
LVL 3

Accepted Solution

by:
jyu_88 earned 300 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

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…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

801 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