1748232 Members
3948 Online
108759 Solutions
New Discussion юеВ

Re: error_in script

 
SOLVED
Go to solution
Soul_1
Respected Contributor

error_in script

Hi

While executing this script

#################
echo "getting the events dump"
Date=$(date)
/opt/OV/bin/ovdumpevents > events
echo "now processing events"
more events |grep OVpatternDelete >list
Value=$(tail -1 list|awk '{print $8}')
EvDate=$(tail -1 list|awk '{print $3, $4, $5, $6, $7}'|cut -c -8,10-)
if [ ${Value} = "OVpatternDelete" && ${Date} = ${EvDate} ]
then
echo "processing mail"
else
echo "no action"
fi

i am getting the following error.

# sh ecschk.sh
getting the events dump
now processing events
ecschk.sh[10]: test: A ] character is missing.
no action


please help me to solve this.

Thanks & Regards
10 REPLIES 10
smatador
Honored Contributor

Re: error_in script

Hi,
replace
if [ ${Value} = "OVpatternDelete" && ${Date} = ${EvDate} ]
by
if [ ${Value} = "OVpatternDelete" -a ${Date} = ${EvDate} ]
HTH
Soul_1
Respected Contributor

Re: error_in script

Hi,

Thanks for the correction.

i replaced the as per your suggestion.

now am getting this error

sh ecschk.sh
getting the events dump
now processing events
ecschk.sh[10]: Jan: A test command parameter is not valid.
no action


Also please tell me the diff in && and -a.i dont have any experience in this.i just simply followed some sytax from google.

THANKS
Solution

Re: error_in script

one of the variables you set is probably evaluating to nothing - so you might want to try:

if [ "${Value}" = "OVpatternDelete" -a "${Date}" = "${EvDate}" ]

The && syntax for "and" doesn't work in a test statement in the HP-UX POSIX shell - the code you got from google was probably for another shell which supports both syntaxes...

HTH

Duncan

I am an HPE Employee
Accept or Kudo
Dennis Handly
Acclaimed Contributor

Re: error in script

>Duncan: The && syntax for "and" doesn't work in a test statement in the HP-UX POSIX shell

If you want to use &&, you need to use [[ ]]:
if [[ "${Value}" = "OVpatternDelete" && "${Date}" = "${EvDate}" ]]; then

Soul_1
Respected Contributor

Re: error_in script

Hi,

Thanks a lot for the information.

now i am facing another error while executing. This command will be executed by the application (as user bin ).i tried a lot with changing permission and all . please have a look into this

Tue Jan 05 12:57:38 Command "/usr/sbin/evdel.sh" returned standard error data:
/usr/sbin/evdel.sh[5]: /tmp/ActionNNM/events: Cannot create the specified file.
/tmp/ActionNNM/events: No such file or directory
list: No such file or directory
rm: events non-existent

Thanks
Dennis Handly
Acclaimed Contributor

Re: error in script

>This command will be executed by the application (as user bin).

Typically bin isn't a real user. How are you logged into bin?)

>"/usr/sbin/evdel.sh" returned standard error data:
/usr/sbin/evdel.sh[5]: /tmp/ActionNNM/events: Cannot create the specified file.

Does the directory /tmp/ActionNNM exist? If not, you can always use "mkdir -p /tmp/ActionNNM" to make sure.
Does that directory have the right permission?
ll -d /tmp/ActionNNM

Soul_1
Respected Contributor

Re: error_in script

Hi

Thanks for the quick response.

I didn't logged in as user bin.But when my application executes command as bin.

ll /tmp/ActionNNM/
total 112
-rw-r--r-- 1 bin bin 19140 Jan 5 13:19 action.log
-rw-r--r-- 1 bin bin 2580 Jan 5 13:19 action1.log
drwxr-xr-x 2 root sys 8192 Jan 5 12:44 back
-rwxr-xr-x 1 bin bin 655 Jan 5 12:51 evdel.sh
-rw-r--r-- 1 bin bin 382 Jan 5 12:54 list

Please check the permissions
Soul_1
Respected Contributor

Re: error_in script

# ll -d /tmp/ActionNNM
drwxr-xr-x 3 root sys 8192 Jan 5 12:54 /tmp/ActionNNM
Dennis Handly
Acclaimed Contributor

Re: error in script

>But when my application executes command as bin.

That's pretty strange. It would make more sense to create a special user and not use one of the system UIDs.

>drwxr-xr-x 3 root sys 8192 Jan 5 12:54 /tmp/ActionNNM

This does not allow user bin to create the file events. root must create the file and chown it to bin:bin, then bin can write to it.
Or maybe you should have bin own the directory?