Script not running correctly


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script not running correctly
# 1  
Old 01-25-2008
Script not running correctly

Hi all,

My script below was working fine till I changed the LOGFILE path (which originally points to a file within the same folder of the script for testing)

Only the event.log file path is changed, the rest are still within the current folder.

Before the change, running the script works. After the change, from the "sed" commands onwards, it doesn't seem to trigger.

I separated the 'sed' part to another script, and ran that on its own, therefore, the commands work.

But somehow putting it together seems to give me a major headache.

Need help quickly.

Thanks.

Code:
#!/bin/sh
integer CURCOUNT
LOGFILE=/var/opt/resmon/log/event.log

#Compare current count line with old count line in oldcount.txt
OLDCOUNT=`cat oldcount.txt | awk '{print $1}'`

CURCOUNT=`wc -l /var/opt/resmon/log/event.log | awk '{print $1}`

if [ "$CURCOUNT" = "$OLDCOUNT" ]; then
        echo "NO Change"
        exit
else

NEWLINES=`expr $CURCOUNT - $OLDCOUNT`

# Read and output new lines to diffline.txt
STARTLINE=`expr $OLDCOUNT + 1`
LASTLINE=$CURCOUNT

awk -v SL=$STARTLINE -v LL=$LASTLINE '
((NR >=SL) && (NR <=LL)) {print  $0}' /var/opt/resmon/log/event.log > diffline.txt

#Updates oldcount.txt with latest value
echo $CURCOUNT > oldcount.txt
exit
fi

sed -ne '/^---/p' -e '/Severity............: CRITICAL/,/^Description of Error/p' -e '/Severity............: MAJORWARNING/,/^Description of Er
ror/p' diffline.txt | sed -ne '/^Severity/p' -e '/^Summary/,/^Description of Error/p' | sed '/^Description/d' | sed '/^$/d' | sed 's/^[ \t]*/
/;s/[ \t]*$//' > diffline2.txt

sed -n '
:a
/Sev/ {
N
/Sev.*Sev/ !{
s/\n/ /
ta
}
P
D
}' diffline2.txt > diffline3.txt

# 2  
Old 01-25-2008
figured it out...

my 'exit' and 'fi' was in the wrong place..:P...

moved it to the end of the script. Works not.

*Result of staring at the code for too long...hehehe...overlook small mistakes...*...Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Why does this awk script not work correctly?

I have a large database with English on the left hand side and Indic words on the left hand. It so happens that since the Indic words have been entered by hand, there are duplicates in the entries. The structure is as under: English headword=Indic gloss,Indic gloss A small sample will... (6 Replies)
Discussion started by: gimley
6 Replies

2. UNIX for Beginners Questions & Answers

Help with function - is placed in script correctly?

Hi Folks - I hope everyone is well. I just need some assistance with a script I've put together. I haven't used functions before so I was wondering if my script is built properly in terms of architecture? The first command of the script shuts down services. Then, the second part finds a... (1 Reply)
Discussion started by: SIMMS7400
1 Replies

3. Shell Programming and Scripting

Shell script worked correctly until I added variable :(

Hi everyone, I have been using a shell script for the last 6 months to copy a database from a POS system, then analyse the database and print the current sales total. This has worked flawlessly, the only issue was that I had hard coded the IP address of the POS and occasionally I would need to... (23 Replies)
Discussion started by: gjws
23 Replies

4. Shell Programming and Scripting

Script runs manually but not correctly from crontab

Hello all, I'm new here and have a question if you don't mind helping me. I have a script that will work if I kick if off manually but not from Cron. My cron entry is this: 05,20,35,50 * * * * /scripts/status.sh > /dev/null 2>&1 The first script (works fine) is this: #!/bin/sh # #... (14 Replies)
Discussion started by: hs3082
14 Replies

5. Shell Programming and Scripting

Script runs manually but not correctly from crontab

Hi all I have this inside a shell script (bash): cd DIRECTORY find . -maxdepth 1 | sed 's#./##' | /usr/bin/xargs -I '{}' chown -Rv '{}' /DIRECTORY/'{}' All the directories in this location are named after usernames, so it simply sets the owner to that of the username of the folder. It... (5 Replies)
Discussion started by: fakesy
5 Replies

6. Programming

Cannot get dbx to work correctly with a running process

Hi everyone, I've been struggling with this for a few weeks now. I'm trying to debug a running process with dbx on an AIX box. The command I'm using is 'dbx -a <pid> core' There is a function I can perform in my application that crashes this process, but it does not show up as crashed in... (0 Replies)
Discussion started by: ctote
0 Replies

7. Shell Programming and Scripting

script not displaying output correctly

Hi, I am having an issue with my script, ofcourse... I am trying to run commands against a remote server, I am pulling the hostnames or IPs from a file list, then looping thru and running the date cmd. I will be running different cmds just trying to get it working first. The ouput isn't... (2 Replies)
Discussion started by: dfezz1
2 Replies

8. Shell Programming and Scripting

Shell script not unzipping and copying correctly

Hi, I am trying to unzip a file( $pfile, it contains a couple of files and 4 folders with subfolders and files) and have its contents go into a directory instead of into a folder in that directory (ZZZZ), I have the following script: #Unzip the build unzip -o "$HOME/ZZZZ/$pfile" -d... (2 Replies)
Discussion started by: SlumberMachine
2 Replies

9. Shell Programming and Scripting

Find cmd not working correctly in script

I am trying to copy 2 types of files so I can archive them. I tested with a set of commands: touch -t $(date -d "-60 day" +%Y%m%d) WORKDIR/REF find TARGETDIR/ -type f -maxdepth 1 -iname \*.out\* -or -iname \*.log\* ! -newer WORKDIR/REF -exec ls -l {} \; This correctly lists any files in the... (2 Replies)
Discussion started by: prismtx
2 Replies

10. UNIX for Dummies Questions & Answers

Script not working correctly

I have a simple script that I want to run every 30 minutes but only when I execute it. I don't want it to be a crontab job. so i have for example date ls -l who sleep 1800 The first time it executes correctly but after the first time it nevers execute back again. It should execute after... (2 Replies)
Discussion started by: elchalateco
2 Replies
Login or Register to Ask a Question