Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.sys.mac.system > #78781 > unrolled thread
| Started by | csampson@inetworld.net (Charles H. Sampson) |
|---|---|
| First post | 2015-08-22 11:55 -0700 |
| Last post | 2015-08-24 05:15 -0400 |
| Articles | 9 — 6 participants |
Back to article view | Back to comp.sys.mac.system
Bash Script Problem csampson@inetworld.net (Charles H. Sampson) - 2015-08-22 11:55 -0700
Re: Bash Script Problem JF Mezei <jfmezei.spamnot@vaxination.ca> - 2015-08-22 15:18 -0400
Re: Bash Script Problem Jolly Roger <jollyroger@pobox.com> - 2015-08-22 19:59 +0000
Re: Bash Script Problem Alan Baker <email@domain.com> - 2015-08-23 00:53 -0700
Re: Bash Script Problem Barry Margolin <barmar@alum.mit.edu> - 2015-08-22 18:48 -0400
Re: Bash Script Problem Jolly Roger <jollyroger@pobox.com> - 2015-08-23 00:44 +0000
Re: Bash Script Problem csampson@inetworld.net (Charles H. Sampson) - 2015-08-22 23:22 -0700
Re: Bash Script Problem Huge <Huge@nowhere.much.invalid> - 2015-08-23 08:13 +0000
Re: Bash Script Problem Barry Margolin <barmar@alum.mit.edu> - 2015-08-24 05:15 -0400
| From | csampson@inetworld.net (Charles H. Sampson) |
|---|---|
| Date | 2015-08-22 11:55 -0700 |
| Subject | Bash Script Problem |
| Message-ID | <1m9k0ik.l4day0m0szjaN%csampson@inetworld.net> |
I'm having a problem with a Bash script. I've spent a lot of time on it and I'm very frustrated. I'm sure I'm going to be more upset when I find out what the solution is. Here are the first few lines of the scipt: #!/bin/bash logfile="file-name-wth-complete-path-containing-no-spaces" datetime=`date +"%y/%m/%d %H:%M:%S"` echo $datetime script started >> $logfile The problem is that the startup message doesnt get put to the logfile. However, later in the script I have datetime=`date +"%y/%m/%d %H:%M:%S"` echo $datetime script finished >> $logfile and that works just fine. OSX 10.4.7. Thanks in advance. Charlie -- Nobody in this country got rich on his own. You built a factory--good. But you moved your goods on roads we all paid for. You hired workers we all paid to educate. So keep a big hunk of the money from your factory. But take a hunk and pay it forward. Elizabeth Warren (paraphrased)
[toc] | [next] | [standalone]
| From | JF Mezei <jfmezei.spamnot@vaxination.ca> |
|---|---|
| Date | 2015-08-22 15:18 -0400 |
| Message-ID | <55d8caee$0$44137$c3e8da3$3a1a2348@news.astraweb.com> |
| In reply to | #78781 |
On 15-08-22 14:55, Charles H. Sampson wrote: > #!/bin/bash > logfile="file-name-wth-complete-path-containing-no-spaces" > datetime=`date +"%y/%m/%d %H:%M:%S"` > echo $datetime script started >> $logfile > > The problem is that the startup message doesnt get put to the logfile. > However, later in the script I have > > datetime=`date +"%y/%m/%d %H:%M:%S"` > echo $datetime script finished >> $logfile > > and that works just fine. > => creates new file >> => appends to existing file. Have you tried ">" for the first echo, and >> for subsequent "writes" to the log file ?
[toc] | [prev] | [next] | [standalone]
| From | Jolly Roger <jollyroger@pobox.com> |
|---|---|
| Date | 2015-08-22 19:59 +0000 |
| Message-ID | <d3s2laFehv8U1@mid.individual.net> |
| In reply to | #78781 |
On 2015-08-22, Charles H. Sampson <csampson@inetworld.net> wrote: > I'm having a problem with a Bash script. I've spent a lot of time on it > and I'm very frustrated. I'm sure I'm going to be more upset when I find > out what the solution is. > > Here are the first few lines of the scipt: > > #!/bin/bash > logfile="file-name-wth-complete-path-containing-no-spaces" > datetime=`date +"%y/%m/%d %H:%M:%S"` > echo $datetime script started >> $logfile > > The problem is that the startup message doesnt get put to the logfile. Interesting. I ran the above code, with no modifications, and a file named "file-name-wth-complete-path-containing-no-spaces" was created on my desktop containing: 15/08/22 12:58:37 script started If you run the above code without any modifications, do you see the same result? -- E-mail sent to this address may be devoured by my ravenous SPAM filter. I often ignore posts from Google. Use a real news client instead. JR
[toc] | [prev] | [next] | [standalone]
| From | Alan Baker <email@domain.com> |
|---|---|
| Date | 2015-08-23 00:53 -0700 |
| Message-ID | <mrbu5u$b4g$1@news.datemas.de> |
| In reply to | #78783 |
On 2015-08-22 19:59:38 +0000, Jolly Roger said: > On 2015-08-22, Charles H. Sampson <csampson@inetworld.net> wrote: >> I'm having a problem with a Bash script. I've spent a lot of time on it >> and I'm very frustrated. I'm sure I'm going to be more upset when I find >> out what the solution is. >> >> Here are the first few lines of the scipt: >> >> #!/bin/bash >> logfile="file-name-wth-complete-path-containing-no-spaces" >> datetime=`date +"%y/%m/%d %H:%M:%S"` >> echo $datetime script started >> $logfile >> >> The problem is that the startup message doesnt get put to the logfile. > > Interesting. I ran the above code, with no modifications, and a file > named "file-name-wth-complete-path-containing-no-spaces" was created on > my desktop containing: > > 15/08/22 12:58:37 script started Same here. > > If you run the above code without any modifications, do you see the same > result?
[toc] | [prev] | [next] | [standalone]
| From | Barry Margolin <barmar@alum.mit.edu> |
|---|---|
| Date | 2015-08-22 18:48 -0400 |
| Message-ID | <barmar-1D8FEE.18481422082015@88-209-239-213.giganet.hu> |
| In reply to | #78781 |
In article <1m9k0ik.l4day0m0szjaN%csampson@inetworld.net>, csampson@inetworld.net (Charles H. Sampson) wrote: > I'm having a problem with a Bash script. I've spent a lot of time on it > and I'm very frustrated. I'm sure I'm going to be more upset when I find > out what the solution is. > > Here are the first few lines of the scipt: > > #!/bin/bash > logfile="file-name-wth-complete-path-containing-no-spaces" > datetime=`date +"%y/%m/%d %H:%M:%S"` > echo $datetime script started >> $logfile > > The problem is that the startup message doesnt get put to the logfile. > However, later in the script I have > > datetime=`date +"%y/%m/%d %H:%M:%S"` > echo $datetime script finished >> $logfile > > and that works just fine. > > OSX 10.4.7. Thanks in advance. > > Charlie Do you have other statements that write to the logfile? I suspect one of them uses > instead of >>, so it's wiping out everything that was logged before it. -- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me ***
[toc] | [prev] | [next] | [standalone]
| From | Jolly Roger <jollyroger@pobox.com> |
|---|---|
| Date | 2015-08-23 00:44 +0000 |
| Message-ID | <d3sjagFi8h8U2@mid.individual.net> |
| In reply to | #78788 |
On 2015-08-22, Barry Margolin <barmar@alum.mit.edu> wrote: > > Do you have other statements that write to the logfile? I suspect one of > them uses > instead of >>, so it's wiping out everything that was logged > before it. That's what I suspect too. -- E-mail sent to this address may be devoured by my ravenous SPAM filter. I often ignore posts from Google. Use a real news client instead. JR
[toc] | [prev] | [next] | [standalone]
| From | csampson@inetworld.net (Charles H. Sampson) |
|---|---|
| Date | 2015-08-22 23:22 -0700 |
| Message-ID | <1m9kwfx.3785tg2r65k0N%csampson@inetworld.net> |
| In reply to | #78781 |
Charles H. Sampson <csampson@inetworld.net> wrote: > I'm having a problem with a Bash script. I've spent a lot of time on it > and I'm very frustrated. I'm sure I'm going to be more upset when I find > out what the solution is. > > Here are the first few lines of the scipt: > > #!/bin/bash > logfile="file-name-wth-complete-path-containing-no-spaces" > datetime=`date +"%y/%m/%d %H:%M:%S"` > echo $datetime script started >> $logfile > > The problem is that the startup message doesnt get put to the logfile. > However, later in the script I have > > datetime=`date +"%y/%m/%d %H:%M:%S"` > echo $datetime script finished >> $logfile > > and that works just fine. > > OSX 10.4.7. Thanks in advance. As I said, many thanks to all who responded. While nobody got it completely right, you gave me the idea of where to look. Elsewhere in the script, I had occurrences of &>, which of course means "write standard output and standard error to ..." It apparently also means "Prepare to write standard output and standard error to that file, even if there's nothing to write." Hence, the startup message got deleted. I changed the occurrences of &> to &>>. According to my Bash manual (by Chet Ramey of CWU and Brian Fox of FSF), this means "append standard output and standard error to ...". However, the 10.4.7 version of Bash is confused by this, saying it got an unexpected occurrence of ">" on the first line where &>> occurred. Since this was for debugging information, I just deleted all occurrences of &>> and things are looking much better. Charlie -- Nobody in this country got rich on his own. You built a factory--good. But you moved your goods on roads we all paid for. You hired workers we all paid to educate. So keep a big hunk of the money from your factory. But take a hunk and pay it forward. Elizabeth Warren (paraphrased)
[toc] | [prev] | [next] | [standalone]
| From | Huge <Huge@nowhere.much.invalid> |
|---|---|
| Date | 2015-08-23 08:13 +0000 |
| Message-ID | <d3tdllFo3emU1@mid.individual.net> |
| In reply to | #78807 |
On 2015-08-23, Charles H. Sampson <csampson@inetworld.net> wrote:
[29 lines snipped]
> I changed the occurrences of &> to &>>. According to my Bash manual (by
> Chet Ramey of CWU and Brian Fox of FSF), this means "append standard
> output and standard error to ...". However, the 10.4.7 version of Bash
> is confused by this, saying it got an unexpected occurrence of ">" on
> the first line where &>> occurred. Since this was for debugging
> information, I just deleted all occurrences of &>> and things are
> looking much better.
Always better to 'touch' such files before writing to them, that way the file
gets created.
My 'bash' is similarly broken to yours, so I do this little dance, where I
copy the log to a tmp file, then append it to the real logfile;
echo "Info - Copying /home to $target/$today ..." 1>&2
/usr/bin/figlet "Copying /home to $target/$today" >> /tmp/$logfile
cp -Pprdv home $target/$today &> /tmp/$$
cat /tmp/$$ >> /tmp/$logfile # This nonsense is because &>> doesn't work
/usr/bin/figlet "=============" >> /tmp/$logfile
--
Today is Setting Orange, the 16th day of Bureaucracy in the YOLD 3181
I don't have an attitude problem.
If you have a problem with my attitude, that's your problem.
[toc] | [prev] | [next] | [standalone]
| From | Barry Margolin <barmar@alum.mit.edu> |
|---|---|
| Date | 2015-08-24 05:15 -0400 |
| Message-ID | <barmar-BA4FC5.05150124082015@88-209-239-213.giganet.hu> |
| In reply to | #78807 |
In article <1m9kwfx.3785tg2r65k0N%csampson@inetworld.net>, csampson@inetworld.net (Charles H. Sampson) wrote: > Charles H. Sampson <csampson@inetworld.net> wrote: > > > I'm having a problem with a Bash script. I've spent a lot of time on it > > and I'm very frustrated. I'm sure I'm going to be more upset when I find > > out what the solution is. > > > > Here are the first few lines of the scipt: > > > > #!/bin/bash > > logfile="file-name-wth-complete-path-containing-no-spaces" > > datetime=`date +"%y/%m/%d %H:%M:%S"` > > echo $datetime script started >> $logfile > > > > The problem is that the startup message doesnt get put to the logfile. > > However, later in the script I have > > > > datetime=`date +"%y/%m/%d %H:%M:%S"` > > echo $datetime script finished >> $logfile > > > > and that works just fine. > > > > OSX 10.4.7. Thanks in advance. > > As I said, many thanks to all who responded. While nobody got it > completely right, you gave me the idea of where to look. Elsewhere in > the script, I had occurrences of &>, which of course means "write > standard output and standard error to ..." It apparently also means > "Prepare to write standard output and standard error to that file, even > if there's nothing to write." Hence, the startup message got deleted. It means to write them -- if they're empty, it writes nothing. But either way, it zeroes out the destination file first. > > I changed the occurrences of &> to &>>. According to my Bash manual (by > Chet Ramey of CWU and Brian Fox of FSF), this means "append standard > output and standard error to ...". However, the 10.4.7 version of Bash > is confused by this, saying it got an unexpected occurrence of ">" on > the first line where &>> occurred. Since this was for debugging > information, I just deleted all occurrences of &>> and things are > looking much better. OS X uses bash 3.x, that manual is for bash 4.x. Bash 3.x has &>filename as a shorthand for >filename 2>&1, but it doesn't have &>>filename. Instead of deleting them, change them to >>filename 2>&1. Since many commands on OS X are different versions from the Linux versions, you should use the man pages on your system rather than web sites to get the definitive documentation. -- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me ***
[toc] | [prev] | [standalone]
Back to top | Article view | comp.sys.mac.system
csiph-web