LC_TIME="en_GB.utf8" not more working since March - linux

On German Linux-system I run script to grep information by date from English document.
LC_TIME="en_GB.utf8" grep -a "\[$(date -d "yesterday" +%b\ %d)" file.log
Since March script don't grep information anymore. Before it worked fine over months.
Manual I see the problem, that not "Mar" but German "Mär" is in search string:
LC_TIME="en_GB.utf8" echo $(date -d "yesterday" +%b\ %d)
Mär 27
Following LC_TIME="en_GB.utf8" is not more working correct.
What can I do?

You are changing LC_TIME for grep and for echo not for date.
echo $(LC_TIME="en_GB.utf8" date -d "yesterday" +%b\ %d)
grep -a "[$(LC_TIME="en_GB.utf8" date -d "yesterday" +%b\ %d)"

Related

Linux illegal date format

#!/bin/bash
DAYS=${2:-0}
DATE=$(date '+%Y-%m-%d' -d "2016-11-20 +$DAYS days")
I am trying to perform the above action in in my shell script but i keep getting this error:
date: illegal time format
usage: date [-jnu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
[-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
2016-12-14 17:31:31,779
Not sure what is wrong
If you are using a non-GNU date command may be the FreeBSD version on a Mac, use the -j flag.
date -j -v+2d -f "%Y-%m-%d" "2016-11-20" +%Y-%m-%d
2016-11-22
to use a variable, just double-quote it
DAYS=2
date -j -v+"$DAYS"d -f "%Y-%m-%d" "2016-11-20" +%Y-%m-%d
2016-11-22

Issue echoing variables in bash script

I was working on a script to echo the date upon login in a different format but once I get down to echoing the result, it gives me a jumbled up output. I've been searching online to see if I'm calling the variables wrong or using wrong ticks somewhere but no luck. I even have echoed each individual variable before and after the problem echo and they echo the proper date/month/day of week. As my script is right now, it only puts out ". which is a Thu" when run. Also, I've been executing it with "sh ./datescript.sh" Any help/additional resources would be appreciated. Thanks!
My Script:
#!/usr/bin/env bash
date=`date` #NOTE: date being used in two different ways
day=`echo ${date} | cut -f1 -d' '`
month=`echo ${date} | cut -f2 -d' '`
date=`echo ${date} | cut -f3 -d' '`
echo "Today is the ${date}th day of ${month}, which is a ${day}."
echo $day
echo $month
echo $date
I can replicate the behaviour if I add $'\r' at the end of month and date assignment lines. Seems like Win/*nix line ending issue.
Run dos2unix or fromdos on the script to fix it.
#!/usr/bin/env bash
day=`date +%A`
month=`date +%B`
date=`date +%-d`
echo "Today is the ${date}th day of ${month}, which is a ${day}."
echo $day
echo $month
echo $date

Using date utility on Linux and AIX

To verify a valid date I use the command line below:
date -d "${DATE}" "+%Y/%m/%d" > /dev/null 2>&1
It works perfectly under Cygwin, but not in my test environment.
Here's some information about my test environment:
uname -a
AIX 152101a07e 3 5 00CDE2314C00
Using the command line:
echo $?
The result is always 1, even if the date is valid.
Do you have any idea why this test fails?
Apparently, your two environments are not running the same version of date. You should check the man page for date in your new environment (run man date). On my machine (OS X), the -d option is used for setting daylight savings time.
For example, the following works for me:
date -j -f "%Y/%m/%d" "2014/07/09" > /dev/null 2>&1
echo $? # 0
date -j -f "%Y/%m/%d" "2014.07.09" > /dev/null 2>&1
echo $? # 1
-j tells it to not try to set my system date. -f means to use the specified format.
Yours may be different, but you can find out the details by reading the manual.

Compare last modification dates of local and remove files

I can get a last modification date of the remote file using
curl --head http://url 2>/dev/null | grep -Po '(?<=^Last-Modified:\s).*$'
This gets me date/time such as
Wed, 04 Sep 2013 19:53:18 GMT
For local file I can use
find /path/file -exec stat \{} --printf="%y\n" \;
and it gets me date/time such as
2012-01-09 09:50:30.000000000 -0500
How can I compare this dat/time with last modification date of the local file? Please note that time zone may be different for remote and local file.
You can actually use date -d to parse the string, as #fedorqui says. Try running the below commands:
$ date -d "$(<your curl command grepped>)" +%s #+%s gets you timestamp.
$ date -d "$(<your find command>)" +%s
To actually compare, you can subtract the timestamps, something like:
$ echo $(( $(date -d "$(<curl cmd>)" +%s) - $(date -d "$(<find cmd>)" +%s) ))

Better quote to execute command on shell script

I'm in doubt of the diference and which one is the better quote to execute a command in shell script.
For example, I have this two examples:
echo "The name of the computer is `uname -n`"
echo "The name of the computer is $(uname -n)"
Which one is better? Or there is no diference?
The $(...) one is generally recommended because it nests easier. Compare:
date -d "1970-01-01 $(echo "$(date +%s)-3600"|bc) sec UTC"
date -d "1970-01-01 `echo \"\`date +%s\`-3600\"|bc` sec UTC "

Resources