Am so happy for the above explanations dude,, Thanks a lot for spending your valuable time for answering this question and doubts...
You're welcome .
Here's an improved, fully commented version of the script:
If you consider that your question has been answered, please mark this thread as SOLVED for the future reference of other users (Go to "Thread tools" and click on "Mark this thread as solved"), and please click on the "Thanks" link in the bottom right corner of this post.
I have created a text file by adding the logs and saved it as mylog.txt
This is the script i written to execute the shell to retrieve the logs from mylog.txt
The issues which i faced is
1) Am using AIX terminal for running the script.
2) Am facing issues in date convertion steps
The stat -c is not recognized as well as date -d is not recognized on the AIX terminal. Its sending a result like " The logs were not Updated for 24 hours for all the logs as it couldnt recognize/read the dates on the logs.
The only problem is date conversion is there any solution for this to run the shell script (not bash) .. Could you please help me out by modifying the date conversion which would be in a readable format for AIX terminal. Thanks for your patience and thanks in advance
Last edited by Franklin52; 07-14-2013 at 06:03 PM..
Reason: Please use code tags
Hi Hari,
When you post code, you should use code tags .
You can do this by writing the word "CODE" inside square brackets at the beginning of the code, and at the end "/CODE", also inside square brackets and without quotes.
Quote:
The issues which i faced is
1) Am using AIX terminal for running the script.
2) Am facing issues in date convertion steps
The stat -c is not recognized as well as date -d is not recognized on the AIX terminal. Its sending a result like " The logs were not Updated for 24 hours for all the logs as it couldnt recognize/read the dates on the logs.
The only problem is date conversion is there any solution for this to run the shell script (not bash) .. Could you please help me out by modifying the date conversion which would be in a readable format for AIX terminal. Thanks for your patience and thanks in advance
I didn't know you were running AIX, but it's OK. Unfortunately, I don't have an AIX box to test an equivalent command . But take a look at this post or this post and see if it helps. It looks like in AIX there is an istat command. Alternatively you can google something like "Linux stat equivalent in AIX" or the like.
As far as the date format is concerned, you can examine date's man page by typing in your terminal "man date" (without quotes) and choose the format that best suits your needs.
Let me explain further:
When you run the date command (without options) you get something like:
In date's man page for AIX you should find a list of format modifiers. For example, the
modifier tells date to convert its output (shown above) to the number of seconds ellapsed since January 1, 1970 (known as Unix epoch).
As to the -d option:
So what this does is:
Display Unix epoch for the current timestamp minus 24 hours.
I'm pretty sure that you can find an equivalent for AIX. The best of luck!
Thanks for the post. I tried by editing the code like
last_mod_time=$(date +%s $line) # this line checks the log's last modification time and converts it to Unix's epoch
last_24_hours=$(date "+%Y %m %d_%H %M %S" "24 hours ago") # this line returns the epoch for the current timestamp minus 24 hours
I dont know whether i have did correctly but i think its giving me a wrong update , actually the log was updated in 24 hours gap but am getting mail like the log was not updated. Could you please modify this alone. IF possible and make it run in AIX terminal. Sorry for bothering you again and again
Thanks for the post. I tried by editing the code like
Unfortunately I don't have an AIX terminal to try . What I can tell by looking at your script is that you're trying to perform a date conversion using wrong parameters.
Something that just came to my mind is which shells you have installed in your system.
Please post the output of the following commands:
1) echo $SHELL
2) chsh -l
3) cat /etc/shells
Another thing. Did you leave the first line of my script intact? (#!/bin/bash)
---------- Post updated at 04:29 PM ---------- Previous update was at 03:35 PM ----------
Ok. Let's give perl a try .
Change this:
with this:
---------------
And this:
with this:
That should do the trick.
i think your idea worked but am not 100% sure about . When i ran the above perl idea added with the bash script , it din showed me any errors or warnings. Just entered the next line. then i ran sh samp.bash it displayed the below output in my mail
I added a log of mine added with ERROR. Thanks for the script .
The file /var/opt/effi/cron.log doesn't exist. Continuing with the next file...
============
The file /var/opt/effi/Doc_cron.log doesn't exist. Continuing with the next file...
============
The file /var/opt/effi/Call_cron.log doesn't exist. Continuing with the next file...
============
The file /var/opt/effi/RSA_cron.log doesn't exist. Continuing with the next file...
============
The file /var/opt/effi/IAS_cron.log doesn't exist. Continuing with the next file...
============
Log /var/opt/hari.log has NOT been updated in the last 24 hours ERROR found in log /var/opt/hari.log============ The file /opt/IBM/FileNet/AE/Router/ConsumerUnderwriting/CUE_cron.log /opt/IBM/FileNet/AE/Router/ConsumerUnderwriting/BuildDoc/CUBuilDoc_cron.log doesn't exist. Continuing with the next file...
============
The file /var/opt/SSPCall_cron.log doesn't exist. Continuing with the next file...
============
The file /var/opt/RSA_cron.log doesn't exist. Continuing with the next file...
============
The file /var/opt/IAS_cron.log doesn't exist. Continuing with the next file...
============
The file /var/opt/Complete_cron.log doesn't exist. Continuing with the next file...
============
The file /var/opt/Extract_cron.log doesn't exist. Continuing with the next file...
============
The file /var/opt/ExtractContentQ_cron.log doesn't exist. Continuing with the next file...
============
Log /var/opt/hari.log has NOT been updated in the last 24 hours ERROR found in log /var/opt/hari.log
============
The file 1 doesn't exist. Continuing with the next file...
============
The file 2 doesn't exist. Continuing with the next file...
============
The file 2 doesn't exist. Continuing with the next file...
============
The file 3 doesn't exist. Continuing with the next file...
============
The file 43 doesn't exist. Continuing with the next file...
============
The file 4 doesn't exist. Continuing with the next file...
============
The file 4 doesn't exist. Continuing with the next file...
============
The file 55 doesn't exist. Continuing with the next file...
============
The file 5 doesn't exist. Continuing with the next file...
============
The file ERROR doesn't exist. Continuing with the next file...
============
The file Error doesn't exist. Continuing with the next file...
============
The file ERROR:Filename doesn't exist. Continuing with the next file...
============
The file error doesn't exist. Continuing with the next file...
============
The file ERROR: I gotcha!! doesn't exist. Continuing with the next file...
============
The file 1 doesn't exist. Continuing with the next file...
============
The file 2 doesn't exist. Continuing with the next file...
============
The file 2 doesn't exist. Continuing with the next file...
============
The file 3 doesn't exist. Continuing with the next file...
============
The file 43 doesn't exist. Continuing with the next file...
============
The file 4 doesn't exist. Continuing with the next file...
============
The file 4 doesn't exist. Continuing with the next file...
============
The file 55 doesn't exist. Continuing with the next file...
============
The file 5 doesn't exist. Continuing with the next file...
============
The file ERROR doesn't exist. Continuing with the next file...
============
The file Error doesn't exist. Continuing with the next file...
============
The file ERROR:Filename doesn't exist. Continuing with the next file...
============
The file error doesn't exist. Continuing with the next file...
============
The file ERROR: I gotcha!! doesn't exist. Continuing with the next file...
============
The file 1 doesn't exist. Continuing with the next file...
============
The file 2 doesn't exist. Continuing with the next file...
============
The file 2 doesn't exist. Continuing with the next file...
============
The file 3 doesn't exist. Continuing with the next file...
============
The file 43 doesn't exist. Continuing with the next file...
============
The file 4 doesn't exist. Continuing with the next file...
============
The file 4 doesn't exist. Continuing with the next file...
============
The file 55 doesn't exist. Continuing with the next file...
============
The file 5 doesn't exist. Continuing with the next file...
============
The file ERROR doesn't exist. Continuing with the next file...
============
The file Error doesn't exist. Continuing with the next file...
============
The file ERROR:Filename doesn't exist. Continuing with the next file...
============
The file error doesn't exist. Continuing with the next file...
============
The file ERROR: I gotcha!! doesn't exist. Continuing with the next file...
============
I have some thing which needs to be cleared in the above output. I don't want to see these lines.
The file 1 doesn't exist. Continuing with the next file...
============
The file 2 doesn't exist. Continuing with the next file...
============
The file 2 doesn't exist. Continuing with the next file...
============
The file 3 doesn't exist. Continuing with the next file...
============
The file 43 doesn't exist. Continuing with the next file...
============
The file 4 doesn't exist. Continuing with the next file...
============
The file 4 doesn't exist. Continuing with the next file...
============
The file 55 doesn't exist. Continuing with the next file...
============
The file 5 doesn't exist. Continuing with the next file...
============
The file ERROR doesn't exist. Continuing with the next file...
============
The file Error doesn't exist. Continuing with the next file...
============
The file ERROR:Filename doesn't exist. Continuing with the next file...
============
The file error doesn't exist. Continuing with the next file...
============
The file ERROR: I gotcha!! doesn't exist. Continuing with the next file...
============
The file 1 doesn't exist. Continuing with the next file...
============
The file 2 doesn't exist. Continuing with the next file...
============
The file 2 doesn't exist. Continuing with the next file...
============
The file 3 doesn't exist. Continuing with the next file...
============
The file 43 doesn't exist. Continuing with the next file...
============
The file 4 doesn't exist. Continuing with the next file...
============
The file 4 doesn't exist. Continuing with the next file...
============
The file 55 doesn't exist. Continuing with the next file...
============
The file 5 doesn't exist. Continuing with the next file...
============
The file ERROR doesn't exist. Continuing with the next file...
============
The file Error doesn't exist. Continuing with the next file...
============
The file ERROR:Filename doesn't exist. Continuing with the next file...
============
The file error doesn't exist. Continuing with the next file...
============
The file ERROR: I gotcha!! doesn't exist. Continuing with the next file...
============
The file 1 doesn't exist. Continuing with the next file...
============
The file 2 doesn't exist. Continuing with the next file...
============
The file 2 doesn't exist. Continuing with the next file...
============
The file 3 doesn't exist. Continuing with the next file...
============
The file 43 doesn't exist. Continuing with the next file...
============
The file 4 doesn't exist. Continuing with the next file...
============
The file 4 doesn't exist. Continuing with the next file...
============
The file 55 doesn't exist. Continuing with the next file...
============
The file 5 doesn't exist. Continuing with the next file...
============
The file ERROR doesn't exist. Continuing with the next file...
============
The file Error doesn't exist. Continuing with the next file...
============
The file ERROR:Filename doesn't exist. Continuing with the next file...
============
The file error doesn't exist. Continuing with the next file...
============
The file ERROR: I gotcha!! doesn't exist. Continuing with the next file...
============
How to make this cleared to get a perfect output like your sample output :
Subject: Log errors and last modification times - Thursday July 11, 2013
To Gabriel Canepa (Gmail)
Log /var/log/alternatives.log was updated during the last 24 hours
No errors found in /var/log/alternatives.log
==============
The file /my/name/is/slim/shady doesn't exist. Continuing with the next file...
==============
Log /var/log/faillog has NOT been updated in the last 24 hours
No errors found in /var/log/faillog
I dont want to see the lines in my log to be presented in the mail as my output resulted.
You get all those "File x doesn't exist" messages because you have added all those files in the log list. Other than that, I don't see much of a difference between the results that you got and mine.
Make sure you list only existing logs, and maybe one or two that don't exist. Then examine the output. If it still doesn't look like you wanted, please send me via email your version of the script and the file that you're using to list all the logs.
hi can any one please help on below .im new to shell scrpting
i need to write a shell script which will check particular log file is presented or not in specific location ,if yes how long it was not modified/not rolling ?if its not modified/log is not rolling script will have to send mail (9 Replies)
Hello,
I wanted to search specific string in the acitve log file and send an email if the search string found in the log.
Log file is written by application all the time. So, script has to search if any new log entry has the specific string for example " sample exception" and send an email. (1 Reply)
HI,
I want to search for a logs which are trace between specific date and time from logs file.
My logs are generated like this :-
Tue Jun 18 05:00:02 EEST 2013 | file_check.sh| Message:script has files to process.
Thu Jun 20 05:00:02 EEST 2013 | file_check.sh| Message:script has files to... (5 Replies)
I have created the script to grep the errors from weblogic logs files and redirecting output to file.txt ...From file.txt I'm using awk command to collect the past 20 mins output...The script running from cron every 15 mins... The script working well...
Now the challenges, I'm trying to use... (27 Replies)
1. The problem statement, all variables and given/known data:
Show all users who are currently logged in, sorted from earliest to latest log in time. The log in time includes the month, day, and time.
2. Relevant commands, code, scripts, algorithms:
finger, who, sort, pipe, head, tail,
... (8 Replies)
Hi,
I want to add some hours and minutes to the current date. For example, if the current date is "July 16, 2012 15:20", i want to add 5 hours 30 minutes to "July 16, 2012 00:00" not to "July 16, 2012 15:20". Please help.
Thanks! (4 Replies)
How can view log messages between two time frame from /var/log/message or any type of log files.
when logfiles are very big and especially many messages with in few minutes, I would like to display log messages between 5 minute interval.
Could you pls give me the command? (1 Reply)
I want to add a crontab entry which should execute for every 4 hours and that 4 hours calculation should begin from the current time.
Normally if I set the crontab entry like this,
00 */4 30 05 * root date >>/tmp/cronout
The above will execute the date command for every 4 hours like... (7 Replies)
Hi All,
I need to get current error messages with time from alert.log.Below is my shell script but it's not working to meet this objective.
could anyone pls share on the above issue for resolution:
####################################################################
## ckalertlog.sh ##... (2 Replies)