Error running script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error running script
# 1  
Old 06-05-2014
Tools Error running script

Hi,

I have the the below script

Code:
more runcda.sh
if [ $(sed -n 's/.*\(ParallelGCThreads=[0-9]*\).*/\1/p' $1_dr) ]; then
echo "ParallelGCThreads Found with Value"
else
echo "ParallelGCThreads Not Found - Add !!"
fi

$ ./runcda.sh output.log
./runcda.sh: test: argument expected
ParallelGCThreads Not Found - Add !!

Why am i getting the bold error and how can i get rid of it ?
# 2  
Old 06-05-2014
Try:
Code:
if [ "$(sed -n 's/.*\(ParallelGCThreads=[0-9]*\).*/\1/p' "$1_dr")" ]; then

Otherwise there will be an error is there when the result is empty.
This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 06-05-2014
Quote:
Originally Posted by mohtashims
Hi,

I have the the below script

Code:
more runcda.sh
if [ $(sed -n 's/.*\(ParallelGCThreads=[0-9]*\).*/\1/p' $1_dr) ]; then
echo "ParallelGCThreads Found with Value"
else
echo "ParallelGCThreads Not Found - Add !!"
fi

$ ./runcda.sh output.log
./runcda.sh: test: argument expected
ParallelGCThreads Not Found - Add !!

Why am i getting the bold error and how can i get rid of it ?
Add quotes:
Code:
if [ "$(sed -n 's/.*\(ParallelGCThreads=[0-9]*\).*/\1/p' $1_dr)" ]; then

Note that the way you have this written, your script will say ParallelGCThreads Found with Value even if there are no digits following the equal sign. If you want to require at least one digit to be present, try:
Code:
if [ "$(sed -n 's/.*\(ParallelGCThreads=[0-9][0-9]*\).*/\1/p' $1_dr)" ]; then

This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Error in running DB query by script

Hi I was trying to fetch data from database. But the number of rows exported were huge so i got the error. Experts please advice. Thanks a lot for your supprt. #: ./script.sh ./script.sh: xmalloc: subst.c:3076: cannot allocate 1401346369 bytes (0 bytes allocated) (2 Replies)
Discussion started by: brij123
2 Replies

2. Shell Programming and Scripting

Error when running script in background

Hi guys, ./test.sh & #!/usr/bin/ksh echo "No.Of Items :" read count echo "Report Time (Min):" read time some other command .... exit 0; thanks (3 Replies)
Discussion started by: asavaliya
3 Replies

3. Shell Programming and Scripting

Error while running script using nohup

Hi, I am running the below script. When i run the script normally it executes fine but when i run the same script using nohup it throws an error as getStatus.sh: syntax error at line 3: `(' unexpected . Can you let me know why it is so? while do . $(dirname $0)/include.sh cd... (2 Replies)
Discussion started by: vignesh53
2 Replies

4. UNIX and Linux Applications

Getting error code when running the script 2 (RC)2

hi All, we have a script to remove the files from particular path,when we tryingto run manually the script went to success and removed the files but the same script which is running by other team it got failed and giving the error "2 (RC)2 "..what is the cause of the failure..and we passing the... (2 Replies)
Discussion started by: nagavenkatesh
2 Replies

5. Shell Programming and Scripting

Error running nawk script

Hi, I was trying to use nawk script given in this link https://www.unix.com/aix/19979-df-output-not-aligned.html but when i do this im getting this error $ df -k|formatDF.nawk -ksh: formatDF.nawk: not found Can anyone help me on this... (6 Replies)
Discussion started by: niteesh_!7
6 Replies

6. Solaris

Error when running script

Hi All, Need your guuys help here. #!/bin/bash { echo "POLICY LIST" echo "====================================" bppllist echo " " echo "POLICY DETAILS" echo "====================================" for type in daily weekly monthly quarterly echo... (6 Replies)
Discussion started by: ronny_nch
6 Replies

7. UNIX for Dummies Questions & Answers

Getting error when running script through crontab

Hi all, I wrote small script for Solaris and when I am running it through command prompt its ok, but when I trying to run it using crontab, i am getting error like: ld.so.1: dbloader: fatal: libACE.so: open failed: No such file or directory /tmp/file.sh: line 5: 8304 Killed ... (4 Replies)
Discussion started by: nypreH
4 Replies

8. Shell Programming and Scripting

error in in running script

Hi all, I have created a script file .sh and had some allias commands, local variable, some grep features, and listing files/directories, and it worked correctly and I got the outputs I am looking for after I run the script . However, some of the grep commands and some other functions did not... (2 Replies)
Discussion started by: aama100
2 Replies

9. Shell Programming and Scripting

Error while running your script -- Balamv

When I run this, I am getting the below error. Why? Pls help me #!/bin/ksh echo Hello World dirs="not_using_0" for entry in *; do && dirs="$dirs $entry" done dirarray=($dirs) index=1 while }" ] ; do echo "${index}: ${dirarray}" index=`expr $index + 1` done while ; do echo -n... (1 Reply)
Discussion started by: balamv
1 Replies

10. UNIX for Dummies Questions & Answers

Error while running a script

Hi all, By running a (command) script I'm getting the following error: .: /usr/bin/test: cannot execute binary file This is the command: $ . test The script (test) is very simple sqlplus user/password @1.sql sqlplus user/password @2.sql Can enyone tell me what the problem is. (5 Replies)
Discussion started by: HarryTellegen
5 Replies
Login or Register to Ask a Question