Solved

Shell Script with e-mail...

Posted on 2000-03-08
7
200 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
Industry Leaders: 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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 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 video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

695 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