Please use code tags when posting code and/or in/output. It makes it much easier to read.
You still have some syntax errors there:
should be
Sorry, that was my bad in the previous post. No commas in defining an array.
Quote:
but it is trying to read from /home/xxx/AppInstance_status.txt.
No, it's not. It is writing into that text file here:
If you want to read the instances from file, instead from an array, just change the for loop like this:
where AppInstances.lst is the file with one entry on a line. So for your previous example, it would be
I could see that it is displaying all the info from the txt file. What I want it to do is, run the commands from the txt file and display in the message only the instances that are not running as required.
I could see that it is displaying all the info from the txt file
What exactly do you mean? Could you please post your log file and elaborate?
Quote:
run the commands from the txt file
Well this is new. What commands? Which file has commands? Why do you want to run the commands from file as opposed from a script, and just read the parameters of the command from a file, as suggested above?
Thank you so much for your support but I really am not getting what I needed.
I basically want it to read from txt file and run the ps -ef grep commands fro 40 apps and give the result in the body of the message in the email alert which ever app is down with the name of the app instance.
When I tried < AppInstance.lst , it says
no such file or directory which I mentioned in the beginning .
OK. Let's call things the right names, because otherwise confusion arises:
The file you posted, AppInstance_status.txt, is not a log file. It is a script (see the '#!/bin/sh' in the first line). It is probably executable and can be run. Most people would give it a different suffix (like .sh), instead of .txt but that's not the most important thing. But it is not gonna do what you want, because there are errors there.
I want to believe you wish to understand this script, so I'm gonna explain it in more detail and point out the errors.
It has multiple sections, that all do the same thing, but more on that later. Let's look at one of the sections:
As I posted before, there is a dramatic difference between single quotes and backticks. Variable SummaryHandler_status is gonna contain the string 'ps -ef | grep -c SummaryHandler' literal, because that's what single quotes do. What you want is the backticks (that's the key to the left of '1' on most keyboards), which give you the output of the command in the backticks:
or, which is the same,
'ps -ef' will print the running processes, and 'grep -c' will count how many occurrences of "SummaryHandler" are present.
So now, SummaryHandler_status will contain an integer.
Just put an echo there to see the difference:
Now you want to test, whether the integer $SummaryHandler_status is 2. This is because if you do 'ps -ef | grep -c SummaryHandler', you'll see at least one line with 'SummaryHandler' in it: the grep process itself. So you want to see 2 lines, one the grep process, and one the SummaryHandler process. The count can also be more than 2, if e.g. there is more than one SummaryHandler process running.
Let's test: is it 2?
Because the -z tests whether the variable is empty, it is not appropriate here.
The test
Will never pass, since SummaryHandler_status is never empty. It contains a number. The test
will never ever pass, because apart from the value of SummaryHandler_status it has the string "-ne 2", and thus is certainly not empty.
OK, now instead of repeating the section for each app, you could store the names of the apps in a text file and in the script do a loop as I suggested before:
If you make a text file named Apps.txt, and put the names of the apps in, one per line:
Then, you can loop through it like this:
However, I noticed that not all the apps should have one instance running, e.g. RTFFramer should have 3 running. So, you could change your text file Apps.txt to store the number of instances that should be running. Like this:
Then you can read this in and test against it:
I inserted 'grep -v grep' there, to correct for the false extra process, so that I don't have to substract one from $status.
Now that should be all you need. Make a new file called checkApps.sh and put this in there:
make this script executable with
Create the text file Apps.txt as I showed above and run it:
And let me know what happened.
Last edited by mirni; 07-24-2011 at 07:16 PM..
Reason: formatting
Hello ALL,
need a BASH script who find file and send email with attachment.
I have 50 folders without sub directories in each generated files of different sizes but with a similar name Rp01.txt Rp02.txt Rp03.txt ...etc. Each directors bound by mail group, I need a script that goes as... (1 Reply)
Hi Everyone,
Im currently using the below code to pull data from a large CSV file and put it into smaller files with just the data associated with the number that I "grep".
grep 'M053' test.csv > test053.csv
Is there a way that I can use grep to run through my file like the example below... (6 Replies)
Hello ,
I am trying to send an email with two attachments . I have tried all previous suggestion in this forum but none worked. I could send one attachment in an email by
uuencode $file "$file" | mailx -m -s "File" xxx@xx.com
but unable to send multiple attachments .
I have tried
... (8 Replies)
Hello. This shouldn't be an unusual problem, but I cannot find anything about it at google or at other search machine.
So, I've made an application using C++ and QtCreator. I 've made a new mime type for application's project files.
My system (ubuntu 10.10), when I right click a file and I... (3 Replies)
Hello ,
I am trying to write a unix shell script to compare folder permission to say drwxr-x-wx and then send an email to my id in case the folders don't have the drwxr-x-wx permissions set for them .
I have been trying to come up with a script for few days now , pls help me:( (2 Replies)
Hi,
This is my text file I'm trying to Grep.
Apple Location Greenland Rdsds dsds fdfd ddsads http Received Return Immediately Received End
My Grep command:
grep only--matching 'Location.*Received'
Because the keyword Received appears twice, the Grep command will stop at the last... (3 Replies)
Hi,
This is my text file I'm trying to Grep.
Apple Location Greenland Rdsds dsds fdfd ddsads http Received Return Immediately Received End
My Grep command:
grep only--matching 'Location.*Received'
e.
Because the keyword Received appears twice, the Grep command will stop at the last... (0 Replies)
hi,
i'm pretty new to this unix. i've been asked to create a shell script which will pick up the email id from a text file(stored in same machine, same directory) searches for that id in another file in which a product name( a one line text) is mentioned against it. then it should send a mail... (0 Replies)
Hi,
I am using the mailx command to send email to multple users. The command works fine when i am sending mail to a single user but when i insert multiple email ids inside the quote it does not work. All the email ids are coming from a property file.Please have a lookt at the property file and... (4 Replies)
Hi
A) I am able to send eMail using mailx from a UNIX ( solaris 8 ) host to my Outlook-email-ID : FName.Surname@Citigroup.com ( This is NOT my actual -eMail-ID). But in Outlook the "From :" eMail address is displayed as
" usr1@unix-host1.unregistered.email.citicorp.com " .i.e the words... (2 Replies)