I'm writing a script that has logging via a simple routine:
LogIt() { Msg="$1" echo "$THISSCRIPT: $Msg" echo "$Msg" >>$LogFile }
#A portion of this script sends a file via ftp: # ftp -vn >$tempfile <<$$EOD : : $$EOD #Then reads the temporary file to log while read line do LogIt $line Done <$tempfile rm -f $tempfile -------------------------------------- All worked fine when I tested the ftp to a temporary file and reading it back to log the output, but once I created it as a cron entry (or so it seems) it now seems to take each line up to the first space:
Connected 220-TCP/IP Copyright 220 Remote 331 230 250 200 local: 227 150-About : :
See anything I'm doing wrong....any better way of handling this?
TIA,
Frank M. Ramaekers Jr. Systems Programmer; MCP, MCP+I, MCSE & RHCE American Income Life Insurance Company Phone: (254) 761-6649 Fax: (254) 741-5777
On Wed, May 09, 2007 at 02:46:49PM -0500, Frank M. Ramaekers alleged:
I'm writing a script that has logging via a simple routine:
LogIt() { Msg="$1" echo "$THISSCRIPT: $Msg" echo "$Msg" >>$LogFile }
#A portion of this script sends a file via ftp: # ftp -vn >$tempfile <<$$EOD : : $$EOD #Then reads the temporary file to log while read line do LogIt $line Done <$tempfile rm -f $tempfile
All worked fine when I tested the ftp to a temporary file and reading it back to log the output, but once I created it as a cron entry (or so it seems) it now seems to take each line up to the first space:
Connected 220-TCP/IP Copyright 220 Remote 331 230 250 200 local: 227 150-About : :
See anything I'm doing wrong....any better way of handling this?
The first line in your function is only logging its first argument, not all arguments; and since you pass $line unquoted, the first word is the first argument.
You could either quote $line: ``LogIt "$line"'', or use all arguments in LogIt: ``Msg="$@"''.
Frank M. Ramaekers Jr. Systems Programmer; MCP, MCP+I, MCSE & RHCE American Income Life Insurance Company Phone: (254) 761-6649 Fax: (254) 741-5777
Sorry no quote today. Visit QLiner.com.
The first line in your function is only logging its first argument, not all arguments; and since you pass $line unquoted, the first word is the first argument.
You could either quote $line: ``LogIt "$line"'', or use all arguments
in
LogIt: ``Msg="$@"''.
-- Garrick Staples, GNU/Linux HPCC SysAdmin University of Southern California
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
That makes sense now...I didn't realize the difference...thanks!
Frank
On Wed, May 09, 2007 at 03:28:53PM -0500, Frank M. Ramaekers alleged:
The first line in your function is only logging its first argument, not all arguments; and since you pass $line unquoted, the first word is the first argument.
You could either quote $line: ``LogIt "$line"'', or use all arguments
in
LogIt: ``Msg="$@"''.
-- Garrick Staples, GNU/Linux HPCC SysAdmin University of Southern California
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
That makes sense now...I didn't realize the difference...thanks!
So now that that makes sense to you, let me say that you should use both solutions :)
Quoting $line ensures that special meta-characters aren't expanded. For example, if $line contained a *, then the shell could expand it with files in the current directory.
And using $@ instead of $1 in LogIt is just more flexible and is closer to your actual intention of "log everything I pass on this line."
Frank M. Ramaekers Jr. Systems Programmer; MCP, MCP+I, MCSE & RHCE American Income Life Insurance Company Phone: (254) 761-6649 Fax: (254) 741-5777 -----Original Message----- From: centos-bounces@centos.org [mailto:centos-bounces@centos.org] On Behalf Of Garrick Staples Sent: Wednesday, May 09, 2007 3:38 PM To: CentOS mailing list Subject: Re: [CentOS] Scripting question
On Wed, May 09, 2007 at 03:28:53PM -0500, Frank M. Ramaekers alleged:
The first line in your function is only logging its first argument,
not
all arguments; and since you pass $line unquoted, the first word is
the
first argument.
You could either quote $line: ``LogIt "$line"'', or use all arguments
in
LogIt: ``Msg="$@"''.
-- Garrick Staples, GNU/Linux HPCC SysAdmin University of Southern California
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
That makes sense now...I didn't realize the difference...thanks!
So now that that makes sense to you, let me say that you should use both solutions :)
Quoting $line ensures that special meta-characters aren't expanded. For example, if $line contained a *, then the shell could expand it with files in the current directory.
And using $@ instead of $1 in LogIt is just more flexible and is closer to your actual intention of "log everything I pass on this line."