Crontab using yesterday date - date

I'm using old version of Unix and i want to run script everyday using yesterday date
My script lets say
30 08 * * * script.ksh dd mm yy
How to make it

You can do:
script.ksh $(date -d yesterday "+\%d \%m \%y")
% is quoted because that is a new-line symbol in a crontab.

Related

command line on esxi cant get date X day ago [duplicate]

This question already has answers here:
Get date of last saturday - BusyBox 1.1.0
(2 answers)
Closed 5 years ago.
I'm currently working on an ESXI and want to get the date X day ago
I have this command line working on other linux :
now=`date +"%Y/%m/%d"`
earlier=`date -d "$now -15 days" +%d/%m/%Y`
but when i try to use it on my esxi server the line :
earlier=`date -d "$now -15 days" +%d/%m/%Y`
is not working, i get the error
date: invalid date '2018/01/30 -4 days'
So I tried to write the date in differents way like american format but still have the error.
the esxi version is 6.0.0
I have searched on internet but i didn't find anything.
Can someone know what is the problem ?
Thank you.
edit: for those having the same problem i got the solution in the comments below
It turns out this is busybox date. Busybox date is very limited in its abilities, but fortunately it supports (undocumentedly) the #seconds syntax:
date -d "#$(( $(busybox date +%s) - 86400 * 7 ))" +%d/%m/%Y
This of course requires that you have a modern version of bash. If this command doesn't work, try typing "bash" and if that works try typing the command again.
If you don't have modern bash...then do you have awk or bc installed? Python? Perl? Basically the tactical goal is to get date to spit out seconds, subtract 7 days worth of seconds, and then feed the output into date again to convert format.
Old
Try this command line. It avoids the $now reference which might confuse some versions of date.
date -d "15 days ago" +%d/%m/%Y
If this doesn't work, can you tell us which version of date you are using? date --version and/or date --help should provide the necessary information.

add minutes to unixtimestamp shell script

I want to add minutes to the unix timestamp. For example -
date1=$(date +%s)
I want to add minutes to the unixtimestamp using shell script. Something like -
datetime.utcnow() + timedelta(minutes=60) in python

How to convert any date to YYYYMMDDHHMMSS using unix shell script?

How to convert any date to YYYYMMDDHHMMSS using unix shell script?
It is not specific date it may any date. how to convert it?
example date format is: 20110101050603
Thanks
Puspa
DATE = "15 Jun 2015 10:10:10"; date -d"$DATE" +%Y%m%d%H%M%S
Output :-
20150615101010
More on Dates
Note this only works on GNU date.
I have read that:
Solaris version of date, which is unable to support -d can be resolve with replacing sunfreeware.com version of date.
Update:-
Use ls command to find all files and use grep command for all files.
ls | grep "[0-9]{14}"
grep command also accepts regular expression.
But it won't validate your file accurate. For example, if a file name is 20151835101010, then it will validate this file. But actually month and date both are wrong.
So my suggestion is to write a shell script to identify valid file name and find oldest of them by processing one by one.

Crontab command not outputting any log

I've been reading this great post:
https://serverfault.com/questions/449651/why-is-my-crontab-not-working-and-how-can-i-troubleshoot-it
And I decided to modify a line of my cron task to output my echos and any problems it might encouter. My cron tab line looks like this:
30 08 * * * /root/scripts_server/backup_daily.sh &>/var/log/bkp_daily.log
The script runs correctly (I can confirm that the backups were made and transfered) and the output file is created (bkp_daily.log), but it is empty.
Can any one point out a problem?
EDIT:
This is an example of a line in the script:
echo "--------------Sincronización de git remotos a locales-----------------------"
I think &> is a bash extension, try using the standard shell syntax:
30 08 * * * /root/scripts_server/backup_daily.sh >/var/log/bkp_daily.log 2>&1

How to simulate "set -o vi" in csh , like we do in ksh?

I used ksh a lot but now moving to csh as this company has all scripts etc written in that.
One thing I loved about ksh was the ease of using the command history.
In case I have to edit the last command or second last command, I could easily press "Escape - k" to cycle through the commands and easily edit them.
csh does not seem to have a good equivalent. It displays all the history of commands then I have to copy paste one of them and then edit.
That's a pain when you want just change the number of in the file name for example :
cat abcdef1 | grep "Linking"
You could use (as a workaround):
"The most commonly used feature of csh command history is "!!" (pronounced "bang bang") which recalls the previous command":
% date
Mon Nov 25 13:52:36 PST 1996
% !!
date
Mon Nov 25 13:52:52 PST 1996
Here some other useful commands.
But you could just work in ksh and make script and whatever in csh.
If it is istalled simply launch:
/bin/ksh