Re: cron error - date command
On Sun 02 Feb 2020 at 17:32:59 (+1100), Keith Bainbridge wrote: > On 2/2/20 5:22 am, songbird wrote: > >it looks questionable to me just in that you > > may be writing to that file at the same time as > > you when you're doing something else that is also > > trying to write to that file. […] > I am simply trying to keep tack of what time I am doing stuff, and > putting the time between the commands does that how I like it. Hope I > don't prove your concerns correct. I will own up IF I notice > anything, though. Isn't this all built into the shell already? If the HISTTIMEFORMAT variable is set, the time stamp information associated with each history entry is written to the history file, marked with the history comment character. When the history file is read, lines beginning with the history comment character followed immediately by a digit are interpreted as timestamps for the following history entry. Cheers, David.
Re: cron error - date command
On 2/2/20 5:22 am, songbird wrote: it looks questionable to me just in that you may be writing to that file at the same time as you when you're doing something else that is also trying to write to that file. Thankyou Songbird and Roberto. The solution was to escape the % signs in crontab (to \%) Thanks again Teemu Songbird, I note your concerns, but to date all is OK I am simply trying to keep tack of what time I am doing stuff, and putting the time between the commands does that how I like it. Hope I don't prove your concerns correct. I will own up IF I notice anything, though. -- Keith Bainbridge keith.bainbridge.3...@gmail.com 0447 667 468
Re: cron error - date command
Keith Bainbridge wrote: > Good evening All > > I have a niggling problem.Any suggestions, please? > > If I run > echo `date +%d%b%Y` >> /home/keith/.bash_history > in a xterm (Mate I think always), I get the expected result: a line in > .bash_history reads > > 2020Feb01 > followed by > echo `date +%Y%b%d` >> /home/keith/.bash_history > > > > I have this line as a cron-job, and constantly get error messages: > > /bin/bash: -c: line 0: unexpected EOF while looking for matching ``' > /bin/bash: -c: line 1: syntax error: unexpected end of file > > and no output to .bash_history > > > Thanks for your suggests it looks questionable to me just in that you may be writing to that file at the same time as you when you're doing something else that is also trying to write to that file. if you want a log put it in /var/log/.log using the rsyslog or in the journal that system-d uses via the logging interfaces. i haven't looked at cron jobs in ages. for putting something into the bash history from the command line use the history -s command so for your above idea i would use: $ history -s `date +%d%b%Y` songbird
Re: cron error - date command
On Sat, Feb 01, 2020 at 09:42:25PM +1100, Keith Bainbridge wrote: > Good evening All > > I have a niggling problem.Any suggestions, please? > > If I run > echo `date +%d%b%Y` >> /home/keith/.bash_history > in a xterm (Mate I think always), I get the expected result: a line in > .bash_history reads > > 2020Feb01 > followed by > echo `date +%Y%b%d` >> /home/keith/.bash_history > > > > I have this line as a cron-job, and constantly get error messages: > > /bin/bash: -c: line 0: unexpected EOF while looking for matching ``' > /bin/bash: -c: line 1: syntax error: unexpected end of file > > and no output to .bash_history > > Hi Keith, I'm not sure what problem you are trying to solve, but let me suggest that you instead set the HISTTIMEFORMAT environment variable. For example $ export HISTTIMEFORMAT="%Y%b%d " $ history | tail 25567 2020Jan31 git log --oneline --graph --branches 25568 2020Jan31 gbp buildpackage --git-tag --git-tag-only 25569 2020Jan31 git log --oneline --graph --branches 25570 2020Jan31 for base in /var/cache/pbuilder/base-* ; do sudo cowbuilder --update --basepath ${base} ; done 25571 2020Jan31 sudo debootstrap --variant=buildd sid /srv/chroot/sid/ http://ftp.us.debian.org/debian/ 25572 2020Jan31 schroot -c source:sid -u root -d tmp -- sh -c 'apt-get update && apt-get dist-upgrade -y && apt-get clean' 25573 2020Jan31 sysctl -n hw.logicalcpu 25574 2020Jan31 grep -c ^processor /proc/cpuinfo 25575 2020Jan31 export HISTTIMEFORMAT="%Y%b%d " 25576 2020Jan31 history | tail Regards, -Roberto -- Roberto C. Sánchez
Re: cron error - date command
On 1/2/20 10:10 pm, Teemu Likonen wrote: If you don't want this % effect you need to escape those characters with backslash: echo `date +\%Y\%b\%d` Thankyou Worked just as I wanted. -- Keith Bainbridge keith.bainbridge.3...@gmail.com 0447 667 468
Re: cron error - date command
Keith Bainbridge [2020-02-01T21:42:25+11] wrote: > echo `date +%Y%b%d` >> /home/keith/.bash_history > I have this line as a cron-job, and constantly get error messages: > > /bin/bash: -c: line 0: unexpected EOF while looking for matching ``' > /bin/bash: -c: line 1: syntax error: unexpected end of file > > and no output to .bash_history The "%" character has a special meaning in crontab file. It is interpreted as the end of line. The rest of the line will be sent to the program as standard input stream. See crontab(5) manual: http://man7.org/linux/man-pages/man5/crontab.5.html If you don't want this % effect you need to escape those characters with backslash: echo `date +\%Y\%b\%d` -- /// OpenPGP key: 4E1055DC84E9DFF613D78557719D69D324539450 // https://keys.openpgp.org/search?q=tliko...@iki.fi / https://keybase.io/tlikonen https://github.com/tlikonen signature.asc Description: PGP signature
Re: cron error - date command
Hi. On Sat, Feb 01, 2020 at 09:42:25PM +1100, Keith Bainbridge wrote: > I have this line as a cron-job, and constantly get error messages: > > /bin/bash: -c: line 0: unexpected EOF while looking for matching ``' > /bin/bash: -c: line 1: syntax error: unexpected end of file > > and no output to .bash_history An output of "crontab -l" would be helpful here. Reco
cron error - date command
Good evening All I have a niggling problem.Any suggestions, please? If I run echo `date +%d%b%Y` >> /home/keith/.bash_history in a xterm (Mate I think always), I get the expected result: a line in .bash_history reads 2020Feb01 followed by echo `date +%Y%b%d` >> /home/keith/.bash_history I have this line as a cron-job, and constantly get error messages: /bin/bash: -c: line 0: unexpected EOF while looking for matching ``' /bin/bash: -c: line 1: syntax error: unexpected end of file and no output to .bash_history Thanks for your suggests -- Keith Bainbridge keith.bainbridge.3...@gmail.com 0447 667 468