Issue while executing script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Issue while executing script
# 1  
Old 09-30-2012
Issue while executing script

Hi,

I'm trying to use the below command in a shell script, but couldn't.
The command is working fine when I'm executing from the dollar prompt i.e. shell.

Command:
Code:
 grep -i fail /home/applmgr/error.log |egrep -i "`date  --date="-4  day" +"%m/%d/%Y"`|`date --date="-4 day" +"%m/%d/%y"`" |egrep -i "dbf|ctl|redo|prop|conf|xml"|wc -l

I tried putting the command in `` and it's throwing the below error.

Code:
-bash: command substitution: line 1: unexpected EOF while looking for matching `"'
-bash: command substitution: line 2: syntax error: unexpected end of file
-bash: command substitution: line 1: syntax error near unexpected token `|'
-bash: command substitution: line 1: `|'
-bash: command substitution: line 1: unexpected EOF while looking for matching `"'
-bash: command substitution: line 2: syntax error: unexpected end of file
date: extra operand `+%m/%d/%y'
Try `date --help' for more information.

And when I tried putting it in $(), it's throwing the error.
Code:
-bash: 3: command not found

Please help me out to resolve the issue.

Regards,
Venkatesh.

Last edited by Scrutinizer; 09-30-2012 at 10:11 AM.. Reason: code tags
# 2  
Old 09-30-2012
What exactly are you trying to achieve with this pipeline? There might be better ways.
# 3  
Old 09-30-2012
I'm searching for the word "failure" in that log file and checking for the date format either 'mm/dd/yy' or 'mm/dd/yyyy' (4 days older).

And in the end only the failures which has any of the keywords mentioned in the egrep command are considered.
# 4  
Old 09-30-2012
With perl:
Code:
dt1=$(date --date="-4 day" +"%m/%d/%Y")
dt2=$(date --date="-4 day" +"%m/%d/%y")

perl -e '$dt1=shift @ARGV;
$dt2=shift @ARGV;
while(<>) {
 $c++ if(/fail/i && /($dt1)|($dt2)/ && /(dbf)|(ctl)|(redo)|(prop)|(conf)|(xml)/i )
}
print $c,"\n"' $dt1 $dt2 /home/applmgr/error.log

And if you want to use your pipeline, modify it as:
Code:
grep -i fail /home/applmgr/error.log|egrep -i "(`date --date="-4 day" +"%m/%d/%Y"`)|(`date --date="-4 day" +"%m/%d/%y"`)" |egrep -i "(dbf)|(ctl)|(redo)|(prop)|(conf)|(xml)"|wc -l


Last edited by elixir_sinari; 09-30-2012 at 09:49 AM..
# 5  
Old 09-30-2012
Just an addition to that , the below command works fine at times and gets error out suddenly. Couldn't understand what's exactly wrong here

---------- Post updated at 07:24 AM ---------- Previous update was at 07:21 AM ----------

Thanks for your reply.I'm trying to understand what's wrong I'm doing with the shell script than getting the perl equivalent.

Can you please help.
# 6  
Old 09-30-2012
Check post #4 now.
Would you post the part of the script where you are using this command pipeline?
Are you trying to use a statement like var=`<your pipeline>`. It seems so. This is one of the reasons for avoiding back-ticks for command substitution. If you need to nest them, you have to escape the back-ticks within the outermost pair of back-ticks.
Try something like var=$(<your-pipeline>)
And you can't have a statement like $(<your-pipeline>) by itself. That will try to execute the output of the command substitution (3 in your case) as a command.

Last edited by elixir_sinari; 09-30-2012 at 09:46 AM..
# 7  
Old 09-30-2012
That's correct, I'm trying to use it like var=$(<command>).
It appears to work at times and fails too. So, Couldn't understand what exactly is wrong with the approach.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issue executing grep command on Solaris

more jdbc.xml <name>Fast_ds/DataSource</name> <property> <name>user</name> <value>COL_USER</value> </property>Command 1: grep -A1 '<name>user</name>' jdbc.xml|grep -v '<name>user</name>'|sed 's/\(<value>\|<\/value>\)//g'| sed -e 's/^*//'Output: Command 2: grep... (5 Replies)
Discussion started by: mohtashims
5 Replies

2. Shell Programming and Scripting

Issue in executing cat (remote ssh)

Hi, I need to ssh remotely to a machine and cat a file assign the value to a variable Script: #!/bin/bash -x value=`cat config.txt` echo "$value" ssh me@xxx.host.com "valu='cat /export/home/test.md5'; echo "$valu"" | tee Execution: $ ./x ++ cat config.txt + value='touch me' +... (5 Replies)
Discussion started by: close2jay
5 Replies

3. Shell Programming and Scripting

Executing Oracle script from UNIX Script

Hi, I am new to UNIX and want to execute oracle script from unix script. I have written below script but i am getting below error. #!/bin/bash file="/home/usr/control/control_file1" while read line do #$line=@$line #echo $line sqlplus tiger/scott@DB @$line exit #echo "$line" done... (3 Replies)
Discussion started by: vipin kumar rai
3 Replies

4. Shell Programming and Scripting

Issue on executing db2 queries through shell script

hi i am trying to execute db2 queries through shell script. it's working fine but for few queries is not working ( those queries are taking time so the script is not waiting to get the complete the execution of that query ) could you please any one help me on this is there any wait... (1 Reply)
Discussion started by: bhaskar v
1 Replies

5. Shell Programming and Scripting

Issue when executing shc command

Hi All, I am trying to create an executable using shc. I have a script which is creating 10 executables. The executables being created have the below issue. The message "Please contact your provider" is displayed even though I am not using the “-e” option. This message is coming for some... (5 Replies)
Discussion started by: temp_user
5 Replies

6. Shell Programming and Scripting

Issue while executing C executable with argument in shell script

Hi All, I am new to this forum and also shell script :) My task is I have to read CSV file get the data from the file and use the data to call c executable with data as argument.And the output from c executable should be stored to new CSV file Please find below my code testfunction() {... (14 Replies)
Discussion started by: ravjot28
14 Replies

7. UNIX for Dummies Questions & Answers

Script dosent exits after executing the script

Hi i wrote a script which dosent exists after executing any help #!/bin/bash netstat -ptlen | grep 10000 if ; then echo "Hive Thrift server is running" exit 0 else echo "Hive Thrift server is down Trying to Bring up the service" | mail -s "ALERT" team@domain.com `nohup hive... (7 Replies)
Discussion started by: vikatakavi
7 Replies

8. UNIX for Dummies Questions & Answers

Script not executing

Hello, I wasn't sure where to post this so I posted it here. I've used UNIX quite a bit, LINUX not so much. For some reason, my LINUX script will not execute if I type in the script name and press enter. I'm in the directory where the script is. test.sh However, when I use ". ./" it... (5 Replies)
Discussion started by: jsanders
5 Replies

9. Shell Programming and Scripting

Variables of executed script available in executing script

Hi, I have a script get_DB_var.ksh which do a data base call and get some variables as below: sqlplus -silent $user/$pass@dbname <<END select col1, col2, col3 from table_name where col4=$1; exit; END Now I want to access all these variables i.e.... (9 Replies)
Discussion started by: dips_ag
9 Replies

10. UNIX for Advanced & Expert Users

Executing a shell script from windows;script present in unix

I need to execute a shell script kept in unix machine from windows. User id, password area available. For eg. There's a shell script wich moves all the logs kept in my home directory to a directory named LOGS. Now i need to get this done through windows; either using a batch file, or java... (4 Replies)
Discussion started by: rajneesh_kapoor
4 Replies
Login or Register to Ask a Question