1826396 Members
3731 Online
109692 Solutions
New Discussion

Re: Script error.

 
SOLVED
Go to solution
Adam W.
Valued Contributor

Script error.

Guru's I have attached a script that several of you helped me with, but I am getting an error on one of my servers whenever it runs. I can't figure out the issue. Below is the error I get:

sed: Function s/ * cannot be parsed.
sed: Function s/ cannot be parsed.
/usr/local/bin/filesystemcheck.sh[66]: emailfile: not found.
"emailfile" [New file]

*************************************************
Cron: The previous message is the standard output
and standard error of one of your crontab commands:
/usr/local/bin/filesystemcheck.sh



Can any of you give me an idea of what is wrong? It runs smoothly on all of my other servers, and all of my server are the same software. HP-UX 11.11 all gold packs applied.
There are two types of people in the world, Marines and those who wish they were.
13 REPLIES 13
Patrick Wallek
Honored Contributor

Re: Script error.

On the problematic server, add the following to the top of your script:

#!/usr/bin/sh -x

Then run it again, capture the output and attach it here.

The '-x' turns on 'debug mode' for the shell.
James R. Ferguson
Acclaimed Contributor

Re: Script error.

Hi:

I see two things based on your attachment.

1. Always begin your script's with a shebang line:

#!/usr/bin/sh

...or whatever interpreter is appropriate.

2. You are missing a 'done' as the last line to match the 'do' loop.

Regards!

...JRF...
Ivan Krastev
Honored Contributor
Solution

Re: Script error.

On lines 42-44 you have CR/LF which breaks line to 2 lines.

exceeded=`bdf | sed '/^Filesystem/d' | head -$count | tail -1 | sed 's/ *
/:/g' | cut -d ":" -f5`

Try to move it to 1 line:
exceeded=`bdf | sed '/^Filesystem/d' |head -$count | tail -1 | sed 's/ * /:/g' | cut -d ":" -f5`


Check all lines for such errors.
regards,
ivan
Adam W.
Valued Contributor

Re: Script error.

There is a shebang line. I forgot to copy it.

Missing a done? If I was missing a done, the script wouldn't work on my other servers. Right?

Crap there is a LB on those lines. I am retarded I swear! BRB fellas.
There are two types of people in the world, Marines and those who wish they were.
Adam W.
Valued Contributor

Re: Script error.

Attached is the debug.
There are two types of people in the world, Marines and those who wish they were.
James R. Ferguson
Acclaimed Contributor

Re: Script error.

Hi (again):

Ivan spotted a very big problem unless it is only a manifestion of posting your script here. That is, you can't split commands across lines. You don't need to confine your line length to a terminal line width although this makes readability, printing and editting easier.

If you want to "split" lines, use the line continuation character. For example at the line 42 Ivan cited, you could break the line into three lines like:

exceeded=`bdf | sed '/^Filesystem/d' | \
head -$count | tail -1 | \
sed 's/ */:/g' | cut -d ":" -f5`

...NOTICE that there are no trailing spaces after the continuation character (\) either.

Regards!

...JRF...
Patrick Wallek
Honored Contributor

Re: Script error.

Perhaps I'm blind, but I didn't see an error in the debug output you posted.
Adam W.
Valued Contributor

Re: Script error.

Very good. No trailing spaces..... got it.

James/Ivan/Patrick, Always a pleasure and you all always know what needs done. One day I will ahve this scripting thing down.
There are two types of people in the world, Marines and those who wish they were.
Adam W.
Valued Contributor

Re: Script error.

Patrick, Ivan was correct in the line break. I made (yet another) rookie error that is so common with me. Thanks to you all.
There are two types of people in the world, Marines and those who wish they were.
James R. Ferguson
Acclaimed Contributor

Re: Script error.

Hi (again) Adam:

> It runs smoothly on all of my other servers...

Why not do (and compare) a simple 'cksum' of the script from the server that doesn't work and any one of the ones that do work? The better be the same. For that matter, re-copy (FTP, scp, etc.) a working copy to the non-working server.

Regards!

...JRF...
Adam W.
Valued Contributor

Re: Script error.

Thanks again guys. YOu all always have the knwledge for the solutions. On elast time. Thanks! Semper Fi!
There are two types of people in the world, Marines and those who wish they were.
Adam W.
Valued Contributor

Re: Script error.

Honestly james the thought didn't cross my mind for some reason. (rookie) Thanks again.
There are two types of people in the world, Marines and those who wish they were.
Dennis Handly
Acclaimed Contributor

Re: Script error.

>JRF: you could break the line into three lines like:
exceeded=`bdf | sed '/^Filesystem/d' | \
head -$count | tail -1 | \
sed 's/ */:/g' | cut -d ":" -f5`

Actually you shouldn't need a backslash after the pipe.

In the original source, all archaic `` should be replaced by $().
Also you can replace the two piped seds by:
sed '/^Filesystem/d' | sed 's/ */:/g'
sed -e '/^Filesystem/d' -e 's/ */:/g'

This is highly inefficient:
# This while loop will check the usage of each line of bdf.
# If the %used field exceeds 95%, an e-mail will be sent to me.

You are doing multiple bdfs each time through the loop. Instead put the bdf output in a file and then read that file in the loop.

And then there is a second loop. The data from the first loop could be processed to provide both outputs. Or read that file.