Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

commandline result

Status
Not open for further replies.

TheDash

MIS
Mar 25, 2004
171
US
Hi,

The following command works at command line but not from a script. Any reason? When I copy paste the same command displayed at runtime on screen (using set -x) , it produces result. However, it doesn't give result from the script.

`egrep ''"'($keyword1"'|'"$keyword2)'"'' /var/adm/syslog/syslog.log`

Thanks.
 
In the script keyword1 and keyword2 have same values than at command prompt ?
The script is interpreted by the same shell as the interactive one ?
Are you sure you need all this single quotes ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
They have same values.

Example:
egrep '(Jul 31|Aug 1)' /var/adm/syslog/syslog.log


This is the output:

Code:
+ egrep '(Aug 1|Aug  2)' /var/adm/syslog/syslog.log
+ 1>> testfile
prompt:/home/user1>cat testfile
prompt:/home/user1>

But when I copy paste egrep '(Aug 1|Aug 2)' /var/adm/syslog/syslog.log >> testfile

it works fine.

I am trying to put the shell variables in awk (keyword1 & keyword2) so, I had to use the quotes. Any ideas?
 
I am trying to put the shell variables in awk
Feel free to post the shell script and/or the awk program.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hi,

The code and results are shown below. As shown, the script doesn't produce any result but when copy pasted the same command gives result

testkw.sh

Code:
#!/usr/bin/sh
. /home/user1/datecalculations.sh
set -x
DAY="`date '+%d'`"
MON="`date '+%m'`"
YEAR="`date '+%Y'`"
yesterday=`calculate_date $DAY $MON $YEAR syslog`
today=`date | cut -c5-10`
egrep ''"'($yesterday"'|'"$today)'"'' /var/adm/syslog/syslog.log >> testfile

Results:

Code:
prompt:/home/user1>sh testkw.sh
+ + date +%d
DAY=02
+ + date +%m
MON=08
+ + date +%Y
YEAR=2004
+ + calculate_date 02 08 2004 syslog
yesterday=Aug 1
+ + cut -c5-10
+ date
today=Aug  2
+ egrep '(Aug 1|Aug  2)' /var/adm/syslog/syslog.log
+ 1>> testfile
prompt:/home/user1>cat testfile
prompt:/home/user1>egrep '(Aug 1|Aug  2)' /var/adm/syslog/syslog.log >> testfile
prompt:/home/user1>cat testfile | wc
3258 43862 340764
prompt:/home/user1>
 
And what about simply this in the shell script ?
egrep "($yesterday|$today)" /var/adm/syslog/syslog.log >> testfile

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
It works.

>cp /dev/null testfile
>sh testkw.sh
>cat testfile | wc
3258 43862 340764

Any reason why? Thanks a lot.
 
Any reason why?
PHV said:
Are you sure you need all this single quotes ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top