Unix/Linux Go Back    


UNIX for Beginners Questions & Answers 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

UNIX for Beginners Questions & Answers


Tags
date, grep, solved

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 12-15-2017   -   Original Discussion by scriptor
scriptor's Unix or Linux Image
scriptor scriptor is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 9 April 2018, 9:00 AM EDT
Posts: 180
Thanks: 21
Thanked 0 Times in 0 Posts
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

Sponsored Links
    #2  
Old Unix and Linux 12-15-2017   -   Original Discussion by scriptor
jgt's Unix or Linux Image
jgt jgt is offline Forum Advisor  
Registered User
 
Join Date: Apr 2007
Last Activity: 20 April 2018, 7:32 AM EDT
Location: 44.21.48N 80.50.15W
Posts: 2,048
Thanks: 2
Thanked 281 Times in 263 Posts
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)
Sponsored Links
    #3  
Old Unix and Linux 12-15-2017   -   Original Discussion by scriptor
drysdalk's Unix or Linux Image
drysdalk drysdalk is offline
Registered User
 
Join Date: Feb 2017
Last Activity: 23 February 2018, 5:25 AM EST
Location: United Kingdom
Posts: 242
Thanks: 12
Thanked 83 Times in 73 Posts
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 Unix and Linux 12-15-2017   -   Original Discussion by scriptor
scriptor's Unix or Linux Image
scriptor scriptor is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 9 April 2018, 9:00 AM EDT
Posts: 180
Thanks: 21
Thanked 0 Times in 0 Posts
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
Sponsored Links
    #5  
Old Unix and Linux 12-15-2017   -   Original Discussion by scriptor
rbatte1's Unix or Linux Image
rbatte1 rbatte1 is offline Forum Staff  
Root armed
 
Join Date: Jun 2007
Last Activity: 19 April 2018, 8:53 AM EDT
Location: Lancashire, UK
Posts: 3,508
Thanks: 1,544
Thanked 689 Times in 619 Posts
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
Sponsored Links
    #6  
Old Unix and Linux 12-17-2017   -   Original Discussion by scriptor
bakunin's Unix or Linux Image
bakunin bakunin is offline Forum Staff  
Bughunter Extraordinaire
 
Join Date: May 2005
Last Activity: 19 April 2018, 10:36 AM EDT
Location: In the leftmost byte of /dev/kmem
Posts: 5,741
Thanks: 112
Thanked 1,667 Times in 1,226 Posts
Quote:
Originally Posted by scriptor View Post


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
Sponsored Links
    #7  
Old Unix and Linux 12-18-2017   -   Original Discussion by scriptor
scriptor's Unix or Linux Image
scriptor scriptor is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 9 April 2018, 9:00 AM EDT
Posts: 180
Thanks: 21
Thanked 0 Times in 0 Posts
thx a lot rbatte1 .
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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
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 08:52 AM.