I want to get Japan time in my shell script. I am using this command
DATE=`TZ=Japan date +"%Y%d%m%H%M"`
echo "Japan Date - "$DATE
This is working on online shell script execution. But if I try this in my .sh file, its giving wrong datetime.
Kindly suggest on the same.
The code which I mentioned above works fine in UNIX environment. I was executing it in windows environment which is not correct. The identifier "TZ=Japan" only identified by UNIX environment. So once again, below code works fine
DATE=TZ=Japan date +"%Y%d%m%H%M"
echo "Japan Date - "$DATE
Use this command to get the GMT time:
$date=[System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId($(Get-Date), [System.TimeZoneInfo]::Local.Id, 'GMT Standard Time')
And this one to get Japanese time and add 9 hours to the time:
$TimeRaised = ([datetime]$date).AddHours(9).ToString('dd/MM/yyyy HH:mm')
Related
So for the life of me I cannot figure out why my script will not take my date command as a variable. I have a script that is run every time a message is received and procmail filters specific messages by their subject line. The script looks like this:
d=$(date +%Y%m%d)
:0 wc
* ^(From|subject).*xxx
| cat&>/xx/xx/xx/xx/MSG:$d && \
chmod xxx /xx/xx/xx/xx/MSG:$d && \
/xx/xx/xx/otherscript.sh /xx/xx/xx/xx/MSG:$d
I have run the date command plenty of times in other scripts and to stdout without any issue, so I am wondering if this is a procmail issue? I have looked at a few different sites about this but still have not found a solution. My end goal is to create unique file names as well as for organization purposes each time a new email comes in.
The other reason for me believing it has something to do with procmail is that it was working fine just 3 months ago (didn't change any files or permissions). I have even tried several variations (only showing a few examples):
$'date +"%Y%m%d"'
$(date)
echo $(date)
I get a variety of files created ranging with it printing MSG:(date), MSG:(date ,etc. MSG:(date appears to like it tries to read the variable but is getting cut off or the space between date and + is causing an issue.
And at the end of my script I send it to another script which also creates a new file with the date appended and it works just fine:
fileOut="/xxx/xxx/xxx/xxx.$v.$(date +"%Y%m%d-%H%M%S").xxx"
prints: xxx.YH8AcFV9.20160628-090506.txt
Thanks for your time :-)
Procmail does not support the modern POSIX shell command substitution syntax; you need to use backticks.
d=`date +%Y%m%d` # or just date +%F
If you want to avoid invoking an external process, the From_ pseudo-header contains a fresh date stamp on many architectures.
In a bash script I have the following:
MES=$(date +"%b")
How can I get the month in english format?
Now if I echo $MES variable, I get abr. But I would like to get apr.
I'm trying to solve this without using if statement or switch. May be is an option...
I have tried date -u but is not working for me.
EDIT:
Finally I have put this line in the first line of script script:
#!/bin/bash
LANG=en_us_8859_1
# Here rest of the script
Now is working, but I can't accept my own answer as valid... I think because I haven't enough reputation in stackoverflow
Use Command Substitution
MES=$(LANG=en_us_88591; date +"%b")
to change the language just for this single call.
I am trying to run the below command in Unix. It doesn't work for the below date:-
$ date "+%m%d%Y" -d "09-Mar-2014 02:06:28"
date: invalid date `09-Mar-2014 02:06:28'
When i change the command slightly, it works.
$ date "+%Y%m%d" -d "09-Mar-2014 03:06:28"
20140309
Can some one explain as to why this is so and is there any solution for this?
The above command works fine without any issues in my HP UX B.11.11 version.
I was able to retrieve in the problematic date format too.
How can I invoke curl command correctly from a shell script?
I have a script that actually works in one environment but doesn't on other:
I've researched a lot but still don't know what the problem is, it has to be related to fact that I'm trying to send a date time parameter that contains a space (which i have replaced by a %20). The shell runs without errors but it is not reaching the URL (I can tell that because I see no activity on the destination service)
dateTo=$(date +"%Y-%m-%d%%20%H:%M:%S")
dateFrom=$(date --date='8 hour ago' +"%Y-%m-%d%%20%H:%M:%S")
/usr/bin/curl -k "https://aurl.com/JobHandlerWeb/JobSchedulerServlet?jobId=2&busSvcId=1&receivedFromDate=$dateFrom&receivedToDate=$dateTo"
I found the issue: file format problem.
I had created the file under Windows, and that was making all the difference. Even though I thought it was the same script running fine in one environment, the file format (end line characters) were different.
Corrected using Notepadd++ --> Edit --> EOL conversion
Thanks for your help attempts
I need a bash script that sets a date for my program. The program must work with a date different from the current one. Is it possible? With:
#!/bin/sh
date 122511462014.30 && myprogram
I get the following message error
date: cannot set date: Operation not permitted
because my script runs with no root privileges.
You can't do it like that. date changes the date for the entire system.
You need something like libfaketime