Home Man
Search
Today's Posts
Register

If you're not sure where to post a Unix or Linux question, post it here. All unix and Linux beginners welcome in this forum!

Script not running

Tags
date, grep, solved

Login to Reply

 
Thread Tools Search this Thread
# 1  
Old 12-15-2017
Script not running

hi

i have a alarm file mentioned as below
Code:
alarm_log.15122017

i want to fetch failure detail but script is not working .
kindly let me now where is the mistake
Code:
 
 #!/bin/bash
cd /scripts/
DATE=`date "+ %d%m%Y"`
ls -lrt | grep -i "alarm_log.$DATE"
cat alarm_log.$DATE |grep -B 1 "failure"| tail -2 >v1.txt
if [ -s v1.txt ]
then
echo "sync fail in ${HOSTNAME}
else
echo "no issue"
fi

# 2  
Old 12-15-2017
Line one may have a leading space.
the directory /scripts may not be accessible.
Line 4 the file alarm.log.$(DATE) might not exist or be readable
Line 8, HOSTNAME is not defined. You probably mean $(hostname)
# 3  
Old 12-15-2017
Hi,

Can you provide more detail on how exactly the script is not working, please ? Are you getting an error, and if so, what is the full text of the error ? If you are not getting an error as such, then if you could explain exactly what is going wrong, perhaps someone here will be able to assist you further. But either way, we'll need to know what the problem and nature of the failure actually is first.
# 4  
Old 12-15-2017
HI

I am getting below error

Code:
 
 ./c.sh 
cat: af02_alarm_log.: No such file or directory
cat: 15122017: No such file or directory
no issue

it seems to me that the line
Code:
cat alarm_log.$DATE |grep -B 1 "failure"

is not treating it as a single file but I treating as 2 file.
can anyone help me
# 5  
Old 12-15-2017
The variable DATE has a space in it. You are setting it as DATE=`date "+ %d%m%Y"`
which includes the space after the +

Try using DATE=`date "+%d%m%Y"`
instead. Can you spot the tiny difference? Your shell can, hence the failures.




Robin
# 6  
Old 12-17-2017
Quote:
Originally Posted by scriptor
Code:
cat alarm_log.$DATE |grep -B 1 "failure"

Amen to what rbatte1 said. Furthermore the line is a "useless use of cat", as the experts call it. This:

Code:
grep -B 1 "failure" "alarm_log.$DATE"

Does the same in less processes and with less taxing the system.

I hope this helps.

bakunin
# 7  
Old 12-18-2017
thx a lot rbatte1 .
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Why script is running sometimes and not running sometimes? Sharma331 Shell Programming and Scripting 3 07-01-2014 07:43 AM
Script will keep checking running status of another script and also restart called script at night ketanraut Shell Programming and Scripting 1 11-20-2013 09:41 AM
Shell Script for continuously checking status of a another script running in background, and immedia ketanraut Shell Programming and Scripting 9 11-13-2013 12:54 AM
Bash shell script to check if script itself is running hedkandi Shell Programming and Scripting 8 11-05-2012 12:48 AM
Running a script in system() call and want the script's output amio Shell Programming and Scripting 9 09-13-2010 02:02 AM
script for reading logs of a script running on other UNIX server vandana.parwani Shell Programming and Scripting 1 07-01-2010 09:57 AM
Running a unix script(which is calling another script inside that) in background rohithji Shell Programming and Scripting 2 11-06-2009 12:52 AM
Running a BATCH script from my korn script with multiparameters prash184u Shell Programming and Scripting 7 07-23-2009 11:41 AM
How to stop a script running in remote server from local script mannepalli Shell Programming and Scripting 1 03-04-2009 07:18 PM
Running from Shell Vs running from RC script vickylife Solaris 2 07-31-2008 09:01 AM


All times are GMT -4. The time now is 06:22 PM.

Unix & Linux Forums Content Copyrightę1993-2018. All Rights Reserved.
UNIX.COM Login
Username:
Password:  
Show Password