I'm getting date from csv file which is in EST format. Tried to convert date to sec and Getting error Invalid date ‘Thu Aug 18 18:59:59 EST 2022’ Please help
#!/bin/bash
set +x
date=`/bin/date`
TodayDateSec="$(/bin/date "+%s")"
while IFS=, read -r Name StartDate EndDate;
do
if [ -z "$EndDate" ]; then
echo "$EndDate details not exists"
else
echo "Name: $Name; StartDate: $StartDate; EndDate: $EndDate";
#date=`/bin/date`
EndDateSec="$(/bin/date -d "$EndDate" +'%s')";
DiffDays="$(( ( EndDateSec - TodayDateSec )/86400 ))"
echo "***********$DiffDays************"
if [[ "$DiffDays" -lt 30 ]]; then
echo "Certificate is going to expire in $DiffDays. Please take required action"
fi
fi
done < sample3.csv
Output:
Name: CertName; StartDate: StartDate; EndDate: EndDate
/bin/date: invalid date ‘EndDate’
***********-19195************
Certificate is going to expire in -19195. Please take required action
Name: sslcertificates; StartDate: Thu Dec 17 19:00:00 EST 2020; EndDate: Thu Aug 18 18:59:59 EST 2022
/bin/date: invalid date ‘Thu Aug 18 18:59:59 EST 2022’
***********-19195************
Certificate is going to expire in -19195. Please take required action
Things that changed recently on my server:
I'm almost sure it's because the dist-upgrade.(few days ago)
I added a new user and added him a library in var/www/html/banana.
so it might be from that too (?) - (2 weeks ago)
Tried installing FastCGI without any success - but this didn't disrupt any regular processing and flow. (2 months ago)
I usually run API queries from my PHP code using forking, and in some point it stopped working for me (it does work, but when getting to heavy query results it stopps).
error.log:
[Sun Aug 28 12:15:03.201994 2016] [:notice] [pid 1882] FastCGI: process manager initialized (pid 1882)
[Sun Aug 28 12:15:03.278176 2016] [mpm_prefork:notice] [pid 1879] AH00163: Apache/2.4.18 (Ubuntu) mod_fastcgi/mod_fastcgi-SNAP-0910052141 configured -- resuming normal operations
running cat /var/mail/root outputs:
From root#banana Sun Aug 28 12:39:01 2016
Return-Path: <root#banana>
X-Original-To: root
Delivered-To: root#banana
Received: by banana (Postfix, from userid 0)
id ABC281005BA; Sun, 28 Aug 2016 12:39:01 +0300 (IDT)
From: root#banana (Cron Daemon)
To: root#banana
Subject: Cron <root#banana> [ -x /usr/lib/php/sessionclean ] && /usr/lib/php/sessionclean
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
Message-Id: <20160828093901.ABC281005BA#YHserver>
Date: Sun, 28 Aug 2016 12:39:01 +0300 (IDT)
Can someone help me debug the problem better and solve it?
Running this script gets true results:
<?php
echo "Is fork? <br/>";
var_dump (extension_loaded('pcntl'));
echo "<br><br> more checks: <br>";
$supports = array();
if (function_exists("pcntl_fork")) $supports[] = "ispcntl";
echo implode(",", $supports);
for ($i = 1; $i <= 5; ++$i) {
$pid = pcntl_fork();
if (!$pid) {
sleep(1);
print "In child $i\n";
exit;
}
}
?>
EDIT: I Tried running that same script on the server without forking and I got all the results right (after waiting a lot and getting my website stuck for a while..)
I'm here on Ubuntu 12.04, and I can see:
$ cat /etc/timezone
America/Phoenix
Accordingly Time will return a time with a non-UTC zone:
$ irb
> Time.now
=> 2013-03-27 13:44:49 -0700
> Time.at 0
=> 1969-12-31 17:00:00 -0700
I can override the system time zone using the TZ environment variable:
$ TZ=UTC irb
> Time.now
=> 2013-03-27 20:47:19 +0000
> Time.at 0
=> 1970-01-01 00:00:00 +0000
Is there anyway I can make this change programmatically, within a Ruby process?
You can also set environment variables from within ruby by accessing the ENV hash:
ENV['TZ'] = 'UTC'
Time.at 0
#=> 1970-01-01 00:00:00 +0000
also see this answer: Set time zone offset in Ruby, It provides a way to write something like
with_time_zone 'UTC' do
# do stuff
end
# now TZ is reset to system standard
You can use Time#gmtime. For example
Time.now
# => Wed Mar 27 16:55:11 -0400 2013
Time.now.gmtime
# => Wed Mar 27 20:55:14 UTC 2013
Time.at(0)
# => Wed Dec 31 19:00:00 -0500 1969
Time.at(0).gmtime
# => Thu Jan 01 00:00:00 UTC 1970
Time#utc also works and is an alias for Time#gmtime
Depending on the use case, ActiveSupport offers a lot of TimeZone related goodness.
$ gem install activesupport
$ irb
> require 'active_support/time' # => true
> Time.zone = 'Pacific Time (US & Canada)' # => "Pacific Time (US & Canada)"
> Time.zone.now # => Wed, 27 Mar 2013 16:14:19 PDT -07:00
ActiveSupport may be a larger dependency than you want, but you shouldn't overlook it.
We are trying to convert the output received from the below code
The current output is in this form
testingwindows,1446727960,1446728560,kkulka11,testingwin
testingwindows1,1446727160,141228560,kkulka11,testingwin
testingwindows2,1446727120,1446728560,kkulka11,testingwin
testingwindows3,1446727960,1446728560,kkulka11,testingwin
The output required is something like
testingwindows from Fri Oct 3 13:51:05 2015 GMT to Mon Nov 9 13:51:05 2015 GMT by kkulka11 for testingwin.
testingwindows1 from Fri Oct 2 13:51:05 2015 GMT to Mon Nov 9 13:51:05 2015 GMT by kkulka11 for testingwin.
testingwindows2 from Fri Oct 2 13:51:05 2015 GMT to Mon Nov 9 13:51:05 2015 GMT by kkulka11 for testingwin.
testingwindows3 from Fri Oct 12 13:51:05 2015 GMT to Mon Nov 9 13:51:05 2015 GMT by kkulka11 for testingwin.
This is my current code
if ( $COMMAND eq 'queryone' ) {
my $msend_query = "$MCELL_HOME\\bin\\mquery";
my #args_query = (
$msend_query,
"-q",
"-c", "$MCELL_HOME\\etc\\mclient.conf",
"-n", "$CS_BLACKOUT_CELL",
"-d",
"-f", "csv",
"-a", "CS_EMB_GBF_BLACKOUTS" ,
"-s", "blackout_host,start_timestamp,stop_timestamp,userid,reason",
"-w", "blackout_host: == '${BLACKOUTHOST}'"
);
system(#args_query);
We tried using perl -pe 's/(\d{10})/gmtime($1)/e'; but not able to convert and it gives this error
'o~}go⌂⌂t⌂x⌂w' is not recognized as an internal or external command,
operable program or batch file.
when we used the code as
if ( $COMMAND eq 'queryone' ) {
my $msend_query = "$MCELL_HOME\\bin\\mquery";
my $mqt = "$MCELL_HOME\\mqt.pl";
my #args_query = (
$msend_query,
"-q",
"-c", "$MCELL_HOME\\etc\\mclient.conf",
"-n", "$CS_BLACKOUT_CELL",
"-d",
"-f", "csv",
"-a", "CS_EMB_GBF_BLACKOUTS",
"-s", "blackout_host,start_timestamp,stop_timestamp,userid,reason",
"-w", "blackout_host: == '${BLACKOUTHOST}'"
) | $mqt;
system(#args_query);
Needed experts quick help and guidance to achieve the output in human-readable format.
Edit:
Updated the code as per Jacob comments but still not received the output as desired. Please suggest
if ( $COMMAND eq 'queryone' ) {
my $msend_query = "$MCELL_HOME\\bin\\mquery";
my #args_query = (
$msend_query,
"-q",
"-c", "$MCELL_HOME\\etc\\mclient.conf",
"-n", "$CS_BLACKOUT_CELL",
"-d",
"-f", "csv",
"-a", "CS_EMB_GBF_BLACKOUTS" ,
"-s", "blackout_host,start_timestamp,stop_timestamp,userid,reason",
"-w", "blackout_host: == '${BLACKOUTHOST}'"
);
chomp;
my #parts = split(/,/, system(#args_query));
$parts[1] = localtime($parts[1]);
$parts[2] = localtime($parts[2]);
printf("%s from %s to %s by %s for %s\n", #parts);
}
Output:
M:\AbhayBackup\PerlKK>test.pl -q -h testingwin
testingwin
sub: testingwin
testingwin,1446727960,1446728560,kkulka11,testingwin
0 from Thu Jan 1 05:30:00 1970 to Thu Jan 1 05:30:00 1970 by for
while (<DATA>) {
chomp;
my #parts = split(/,/, $_);
$parts[1] = localtime($parts[1]);
$parts[2] = localtime($parts[2]);
printf("%s from %s to %s by %s for %s\n", #parts);
}
__DATA__
testingwindows,1446727960,1446728560,kkulka11,testingwin
testingwindows1,1446727160,141228560,kkulka11,testingwin
testingwindows2,1446727120,1446728560,kkulka11,testingwin
testingwindows3,1446727960,1446728560,kkulka11,testingwin
Output:
testingwindows from Thu Nov 5 05:52:40 2015 to Thu Nov 5 06:02:40 2015 by kkulka11 for testingwin
testingwindows1 from Thu Nov 5 05:39:20 2015 to Sun Jun 23 07:09:20 1974 by kkulka11 for testingwin
testingwindows2 from Thu Nov 5 05:38:40 2015 to Thu Nov 5 06:02:40 2015 by kkulka11 for testingwin
testingwindows3 from Thu Nov 5 05:52:40 2015 to Thu Nov 5 06:02:40 2015 by kkulka11 for testingwin
Edit: based on your most recent update to the question, I now believe that you're trying to capture the output of the command and process it. Since you haven't provided a minimal, complete, and verifiable example, and because I have no idea what mquery is and you haven't provided an explanation for that, either, I present to you this guess:
if ($COMMAND eq 'queryone') {
my #lines = `$MCELL_HOME\\bin\\mquery -q -c $MCELL_HOME\\etc\\mclient.conf -n $CS_BLACKOUT_CELL -d -f csv -a CS_EMB_GBF_BLACKOUTS -s blackout_host,start_timestamp,stop_timestamp,userid,reason -w blackout_host: == '${BLACKOUTHOST}'`;
for (#lines) {
chomp;
my #parts = split(/,/, $_);
$parts[1] = localtime($parts[1]);
$parts[2] = localtime($parts[2]);
printf("%s from %s to %s by %s for %s\n", #parts);
}
}
I'm here on Ubuntu 12.04, and I can see:
$ cat /etc/timezone
America/Phoenix
Accordingly Time will return a time with a non-UTC zone:
$ irb
> Time.now
=> 2013-03-27 13:44:49 -0700
> Time.at 0
=> 1969-12-31 17:00:00 -0700
I can override the system time zone using the TZ environment variable:
$ TZ=UTC irb
> Time.now
=> 2013-03-27 20:47:19 +0000
> Time.at 0
=> 1970-01-01 00:00:00 +0000
Is there anyway I can make this change programmatically, within a Ruby process?
You can also set environment variables from within ruby by accessing the ENV hash:
ENV['TZ'] = 'UTC'
Time.at 0
#=> 1970-01-01 00:00:00 +0000
also see this answer: Set time zone offset in Ruby, It provides a way to write something like
with_time_zone 'UTC' do
# do stuff
end
# now TZ is reset to system standard
You can use Time#gmtime. For example
Time.now
# => Wed Mar 27 16:55:11 -0400 2013
Time.now.gmtime
# => Wed Mar 27 20:55:14 UTC 2013
Time.at(0)
# => Wed Dec 31 19:00:00 -0500 1969
Time.at(0).gmtime
# => Thu Jan 01 00:00:00 UTC 1970
Time#utc also works and is an alias for Time#gmtime
Depending on the use case, ActiveSupport offers a lot of TimeZone related goodness.
$ gem install activesupport
$ irb
> require 'active_support/time' # => true
> Time.zone = 'Pacific Time (US & Canada)' # => "Pacific Time (US & Canada)"
> Time.zone.now # => Wed, 27 Mar 2013 16:14:19 PDT -07:00
ActiveSupport may be a larger dependency than you want, but you shouldn't overlook it.