Ask a Question related to Debian, Design and Development.
-
Lance Hoffmeyer #1
cron bash date
Hello,
I am trying to run a bash script in cron. I originally wanted
it to run at 11:59pm on the last day of every month. February
will always cause problems because of leap years. Therefore,
I decided to run cron on the first day of every month using
the @month parameter.
The problem is that I want the month to reflect the previous month.
MON=$((`date +%m`-1))
This will work for every month except January where instead of getting 12
I get 0. 2 questions
1) How can I modify the above line so that if `date *%m`-1 = 0 then MON=12
2) I want the output to be 01-09 and not 1-9. How can I change the format
to add a zero? +%m usually adds a zero but subtracting 1 causes the 0
to be removed.
Lance
--
To UNSUBSCRIBE, email to [email]debian-user-request@lists.debian.org[/email]
with a subject of "unsubscribe". Trouble? Contact [email]listmaster@lists.debian.org[/email]
Lance Hoffmeyer Guest
-
time -l date ==> bash: -l: command not found Bug?
"time" doesn't seem to accept any options. The first thing on the line after "time" is taken as the utility to execute. I need the -l option. Am I... -
problem using bash variables with command-line perl in bash script
Hi! I have a problem with variables when using command-line perl in a bash script. The script should update a date (in 2003-10-10 form) if the... -
Bash quoting
On Thu, 31 Jul 2003 10:32:42 +1200, Jochen Daum <jochen.daum@cans.co.nz> wrote: http://uk.php.net/manual/en/function.escapeshellarg.php --... -
bash script help
okay, i want a script i want in bash to log into a telnet session and use a file temp.txt to get the user name something like: telnet -l... -
bash: let exp ? exp : exp problem
Hello, I am trying to get a bash script to work which will hibernate till 1:00 am, it appears to work OK # ensure script executes next at 1:00am... -
David Z Maze #2
Re: cron bash date
Lance Hoffmeyer <lance@augustmail.com> writes:
crontab(5) doesn't suggest a good way to do this, no. So yeah,> I am trying to run a bash script in cron. I originally wanted
> it to run at 11:59pm on the last day of every month. February
> will always cause problems because of leap years. Therefore,
> I decided to run cron on the first day of every month using
> the @month parameter.
running early (say, 12:03 AM) on the first of the month is easy:
3 0 1 * * /usr/local/sbin/ourscript
How about:> The problem is that I want the month to reflect the previous month.
>
> MON=$((`date +%m`-1))
MON=`date -d yesterday +%m`
date(1) seems to think "yesterday" is exactly 24 hours ago, if you're
looking at other fields. (Or maybe it's exactly a day ago; this makes
a difference around daylight savings.)
--
David Maze [email]dmaze@debian.org[/email] [url]http://people.debian.org/~dmaze/[/url]
"Theoretical politics is interesting. Politicking should be illegal."
-- Abra Mitchell
--
To UNSUBSCRIBE, email to [email]debian-user-request@lists.debian.org[/email]
with a subject of "unsubscribe". Trouble? Contact [email]listmaster@lists.debian.org[/email]
David Z Maze Guest
-
Vineet Kumar #3
Re: cron bash date
* David Z Maze (dmaze@debian.org) [030801 07:13]:
Oh yeah, I forgot about that, duh! =p That's way cleaner than my daily> Lance Hoffmeyer <lance@augustmail.com> writes:
>>> > I am trying to run a bash script in cron. I originally wanted
> > it to run at 11:59pm on the last day of every month. February
> > will always cause problems because of leap years. Therefore,
> > I decided to run cron on the first day of every month using
> > the @month parameter.
> crontab(5) doesn't suggest a good way to do this, no. So yeah,
> running early (say, 12:03 AM) on the first of the month is easy:
>
> 3 0 1 * * /usr/local/sbin/ourscript
>>> > The problem is that I want the month to reflect the previous month.
> >
> > MON=$((`date +%m`-1))
> How about:
>
> MON=`date -d yesterday +%m`
touching a file idea.
date actually understands a pretty wide array of expressions. So if> date(1) seems to think "yesterday" is exactly 24 hours ago, if you're
> looking at other fields. (Or maybe it's exactly a day ago; this makes
> a difference around daylight savings.)
"yesterday" isn't to your liking, you can also use $(date -d "24 hours
ago"). Also, I think the OP will then easily see how to have a script
running early on the first of the month can give the date of 23:59
yesterday, by, say, running at 00:05 and asking date for "6 minutes
ago".
good times,
Vineet
--
[url]http://www.doorstop.net/[/url]
--
--Nick Moffitt
A: No.
Q: Should I include quotations after my reply?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
iD8DBQE/KtzW1nIkYEQE+iMRAvQMAJ4iHy3MdCgjsE6fOho9A7UM+zcUpw CeOYB/
wxjOUc07TVE4Ho/653tn2wI=
=zGiI
-----END PGP SIGNATURE-----
Vineet Kumar Guest



Reply With Quote

