Writing a UNIX script from LOG to provide return code.
Folks -
Firstly, I do apologize that my first post here is a question. I am quite familiar with UNIX since our application is running on it. We are trying to automate a few things on our end and I am challenged with a task in hand that requires UNIX scripting. I am totally a newbie in UNIX scripting and I have started learning it but this task seems to be a little complex for me.
Is there only one execution completed per log file? Or are there multiple executions?
If there's only one, then it's pretty simple.
Also, I assume you mean to return a binary return code, not text to stdout.
Put that in a file, maybe name it checklog, use chmod to make it executable and use it like this:
checklog logfile
If the argument file doesn't exist, test -f will return 1 without doing the grep.
If the file exists and the quoted text is not found, grep will quietly return 1.
If both tests succeed, 0 is returned.
This code looks very straight-forward but the only problem is this particular log file will have entries for past executions as well. I am going to try to keep separate log file for different 'Events' to avoid the log file from capturing mutiple 'Event' executions at the same time.
I am jut throwing this idea out there, can we have a secondary log file which is generated from the master log file but it only captures the current execution with an override function? if this is somewhat possible we can potentially have the script you built to go against the secondary log file all the time.
This does sound a little complex to me, let me know what you think?
Here's a slight modification that uses grep to find all the execution completed lines and pipe them to tail, which only passes on the last one. Finally, grep tests to see if it was successful. So this will give a result of the last entry in the file.
I believe that would do the trick!! I am trying to test this out from my environment and I have done the following;
1. I have created a checklog.scp file with the following code below
2. I made the above file executable
Now I am not quite sure about 2 things;
1. If I should try to embed this code on my existing Unix script file (TR01.scp) which I created to trigger the event (See the Code Below)
2. Since your code does not specifiy the location of the log file to perform the grep, I am not sure where to place this file.
Ideally, I would like to see the return code when I execute the TR01.scp
Thanks for all your help Ken!!
---------- Post updated at 03:05 PM ---------- Previous update was at 08:56 AM ----------
Ken -
I finally broke the deadlock... of course your idea was the inpiration to begin with. I tweaked it a little after getting some additional ideas. The script is as below;
I am using mutt on ksh Unix to send emails to addresses plucked from the database. If the "To:" email address is not longer valid and so the email is not sent to the "To:" recipient, but is sent to the valid cc address, I need to be able to get an error code returned to the shell script so that... (3 Replies)
Hi,
Does anyone here can guide me to understand how is return code works in a parent-child relation with a simple example?
I have a request to build the script with return code in a child script, but i want to understand how does child script can return a code to the parent, stated if its... (4 Replies)
Hi
I'm writing a shell script that connects to oracle database and fires query to check the availability of data in a table. In case of no data found then what will be the return code and how to handle in that in variable. Kindly provide with an example for better understanding... Thanks... (1 Reply)
Hi All,
I am writing a unix shell script. I have a file called Results.txt which stores 4 fields separated by pipe. i.e. a pipe delimited file. I want to loop through each record of this file and store each of these 4 fields into variables. I have read can be done through awk but I have never... (7 Replies)
Create an executable script file called "newname" that will perform the followings:
1. Rename a file upon the user's request. If the file exists, prompt the user for confirmation before renaming the file. The screen should prompt the user for
a. "Name of file you want to rename." Use the "\c"... (7 Replies)
I am working on writing scripts. Here is a script I need help with. I have also wrote what I think it is. I would really appreciate any help that I can get.
Create an executable script file called "newname" that will perform the followings:
1. Rename a file upon the user's request. If the... (2 Replies)
Hi Folks,
I posted a few days ago, thanks for the responses. My original question was for renaming files of sort 3p2325294.dgn in a directory containing multiple files. I need to drop the first 2 characters and the last in a unix script using Perl. How does it differ from using the Unix... (1 Reply)
hey all,
I have a simple script
#!/bin/bash
./cron.sh test_a.txt &
./cron.sh test_b.txt &
wait
I want to invoke another program based on the return status of the above calls. How am I were to get that? Thanks! (2 Replies)
How to find out whether the command I executed is successful or unsuccessful(at commandlinet)
Eg:
say i execute the following command at command line
rm *
How do i find out whether my previous command is a success or failure.
Thankyou.
Best Regards,
Ram. (1 Reply)
OS: Solaris
Shell : KSH
Please help me in writing a script that captures a error message from a log file ( which updates continiously ) and send an email alert as soon as the systems throws a error message into that log.
i.e With out monitoring the log
Thanks in advance.. (1 Reply)