Need help! command working ok when executed in command line, but fails when run inside a script!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help! command working ok when executed in command line, but fails when run inside a script!
# 1  
Old 12-02-2010
Need help! command working ok when executed in command line, but fails when run inside a script!

Hi everyone,

when executing this command in unix:
Code:
echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csv

It works fine, but running this command in a shell script gives an error saying that there's a syntax error.

here is content of my script:
Code:
tdbsrvr[Support]$ vi hc.sh
"hc.sh" 22 lines, 509 characters 
. oraenv
echo "Please Enter Username:"
read usrnm
echo "Please Enter Password:"
read pswd

sh que.sh $usrnm $pswd > query1.txt
sh que2.sh $usrnm $pswd > query2.txt
sh que3.sh $usrnm $pswd > query3.txt

echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csv
echo "WM7 Stuck Alarms:", $(cat query2.txt) > b.csv
echo "WM7 Active Files:", $(cat query3.txt) > c.csv

cat a.csv b.csv > 1.csv
cat 1.csv c.csv > 2.csv

echo "Please enter email address:"
read eadd

uuencode 2.csv 2.csv | mailx -s "Health Check" $eadd

upon executing this script by using "sh hc.sh", it gives me this error after inputting username and password:
Code:
tdbsrvr[Support]$ sh hc.sh
ORACLE_SID = [WM7TEST] ? WM7TEST
Please Enter Username:
wtest
Please Enter Password:
wtest
hc.sh: syntax error at line 11: `(' unexpected

Line 11 points to this command: echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csv

So i tried running the command outside the script and it worked just fine. but running this script gives me a syntax error message regarding this command! HELP!
WHAT COULD BE WRONG??? PLEASE HELP ME!

Last edited by Scott; 12-02-2010 at 06:22 AM.. Reason: Please use code tags
# 2  
Old 12-02-2010
Try
Code:
echo "WM7 Fatal Alerts:", `cat query1.txt` > a.csv

instead of
Code:
echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csv

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 12-02-2010
try this:

Code:
echo "WM7 Fatal Alerts:",`cat query1.txt` > a.csv

R0H0N
# 4  
Old 12-02-2010
ok will try that now. THANKS!

---------- Post updated at 06:17 PM ---------- Previous update was at 06:11 PM ----------

wow that worked FINE! THANK YOU SO MUCH BARTUS AND ROHON!
# 5  
Old 12-02-2010
just in case.. try if the below one works..
Code:
echo "WM7 Fatal Alerts:, $(cat query1.txt)" > a.csv

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace string works on command-line but fails when run from shell script

I wish to replace "\\n" with a single white space. The below does the job on command-line: $ echo '/fin/app/scripts\\n/fin/app/01/sql' | sed -e 's#\\\\n# #g'; /fin/app/scripts /fin/app/01/sql However, when i have the same code to a shell script it is not able to get me the same output:... (8 Replies)
Discussion started by: mohtashims
8 Replies

2. Shell Programming and Scripting

Listen sharp time to run a command inside a script

Hello, Just wondered if there is any possibility to run a command at sharp time inside a script in linux. My question is not about crontab Example: #!/bin/bash cd /home/database for i in * do command 1 if time is 19:00, day is Monday then run command2 if time is 20:00, day is... (10 Replies)
Discussion started by: baris35
10 Replies

3. Shell Programming and Scripting

Capture run time of python script executed inside shell script

I have bash shell script which is internally calling python script.I would like to know how long python is taking to execute.I am not allowed to do changes in python script.Please note i need to know execution time of python script which is getting executed inside shell .I need to store execution... (2 Replies)
Discussion started by: Adfire
2 Replies

4. Shell Programming and Scripting

Run bash command inside zsh script

Hi, I would like to run following code in bash inside a zsh script. (In this case is output unfortunately very different if you run it in zsh). I tried to put "bash" in front of the code but I obtained following error message "bash: do: No such file or directory " eve though I merged the whole... (7 Replies)
Discussion started by: kamcamonty
7 Replies

5. UNIX for Dummies Questions & Answers

Set Command to output a log of every command executed in the script

Hi Guys, I like to output every command executed in the script to a file. I have tried set -x which does the same. But it is not giving the logs of the child script which is being called from my script. Is there any parameters in the Set command or someother way where i can see the log... (2 Replies)
Discussion started by: mac4rfree
2 Replies

6. Shell Programming and Scripting

sed command not working inside ksh script but works fine outside

Hi, I am a bit confused ,why would a sed command work fine outside of ksh script but not inside. e.g I want to replace all the characters which end with a value and have space at end of it. so my command for it is : sed -i "s/$SEPARATOR /$SEPARATOR/g" file_name This is working fine in... (8 Replies)
Discussion started by: vital_parsley
8 Replies

7. Shell Programming and Scripting

SH script, variable built command fails, but works at command line

I am working with a sh script on a solaris 9 zone (sol 10 host) that grabs information to build the configuration command line. the variables Build64, SSLopt, CONFIGopt, and CC are populated in the script. the script includes CC=`which gcc` CONFIGopt=' --prefix=/ --exec-prefix=/usr... (8 Replies)
Discussion started by: oly_r
8 Replies

8. Shell Programming and Scripting

Bash- Command run from script does not pass full parameters with spaces inside

There's a JavaScript file that I call from command line (there's a framework) like so: ./RunDiag.js param1:'string one here' param2:'string two here' I have a shell script where I invoke the above command. I can run it in a script as simple as this #!/bin/bash stuff="./RunDiag.js... (4 Replies)
Discussion started by: AcerAspirant
4 Replies

9. Shell Programming and Scripting

sudo command is not working inside a script when placed in cron

Hi All, i have a cron entry like 0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57 * * * * /amex/sssmonitor/dss_chk.ksh and the script is like #!/bin/ksh file=`uname -n` > /sunmast/projects/oasis/COREDEV/Dss$file.log > /tmp/output_sss today=`date` varb=`ps -ef | grep... (5 Replies)
Discussion started by: usha rao
5 Replies

10. Shell Programming and Scripting

Run the command inside perl script

I have a command which will run fine in a unix command prompt. Can you tell how to interprete this command inside perl script...... The command is : perl -pe 's/(\|333\}.*)\}$/$1|1.6}/' FIA.txt This will search for the number 333 and appends 1.6 at the end of that line....... (1 Reply)
Discussion started by: vinay123
1 Replies
Login or Register to Ask a Question