I have the following relevant lines in a csh script:
#!/bin/csh -xv
set dvar = `date +"^%m\/%d\/%y"`
set filedate = `date +%b%d%Y`
set grepstring = "grep "\"$dvar\"" </home/user/log/logfile"
set outstring = ">> serverlog_$filedate.txt"
grep "$dvar" <logfile >serverlog_$filedate.txt
ssh SERVER1 \"\"$grepstring\"\" $outstring
The first grep on the local log file works great, but the SSH grep writes its output to the remote directory.
The line is coming out of the batch file as:
ssh SERVER1 ""grep "^01\/05\/10" <home/user/log/logfile"" >> serverlog_Jan052010.txt
When I type it in (with one less set of quotes of course) it works fine, I just can't get this to work from a csh script.
How would you get this command to output to the specified file on the local machine?
EDIT: Here is the final result that worked thanks to womble:
#!/bin/csh
set dvar = `date +"%m\/%d\/%y"`
set filedate = `date +%b%d%Y`
grep "^$dvar" logfile > serverlog_$filedate.txt
ssh SERVER1 grep "^$dvar" /home/user/log/logfile >> serverlog_$filedate.txt
That script makes my eye bleed. Get rid of all of the variables storing fragments of the command (and the unnecessary input redirect on the
grep
), and see where that gets you. The quoting is almost certainly screwed up in ways you don't even want to imagine. In bourne shell, I'd write something like this:If it's at all possible:
If you need to be able to change the redirection, at least in Bash and sh, you can do: