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
Related
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.
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.
I have the problem,that the following code doesn't work.
start "" "datetime.exe" +%s -d "!timestamp!">tmp_datetime.txt
in cmd it works well, the variable timestamp is in the right Format.
for cmd I type the following
datetime.exe +%s -d "YYYY-MM-ddTHH:mm:ss"
and back comes the date as unix timestamp.
After running my Batch file with the start command, the tmp_datetime.txt is empty
Please try to use "call" instead of "start". Start will open a new window. I think there goes the problem with.
So try this one:
call datetime.exe +%s -d "!timestamp!">tmp_datetime.txt
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.
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