actual date in stdout outputfile? - service

I want to run a service an my Ubuntu-machine with an outputfile (StandardOutput).
The outputfile should have the actual date in its filename and should change every day.
Is this somehow possible?
If "yes", how?
thanks for help

Related

Bash script to modify the last modified date using the file name

I downloaded all the pictures from an old spanish social network and the Last modified date is the date that I downloaded the file instead of the real date. I would like to order all the pictures by Last modified date to upload to google photos using the correct date.
I know the real date because the image name has the date and time and I would make a script to change de last modified date using the name of the file. I don't care about the time.
Name of the file format: "yyyy-mm-dd hh-mm-ss.jpg"
I'm using windows, but is not a problem to install Unix to execute some bash script, because it may probabbly be easier.
Is there any way to do this?
Thanks in advance
You can use powershell $(Get-Item *Filename*).creationtime=$(Get-Date "mm/dd/yyyy hh:mm am/pm") in a batch file or command prompt to change the creation date of a file. for more information look at this. In your case you could do:
for %%i in (<folder with all the files path>) do (
set name=%%~i
set name=%name:~0,19%
powershell $(Get-Item %%~i).creationtime=$(Get-Date "%name:~5,2%/%name:~8,2%/%name:~0,4% %name:~11,2%:%name:~14,2%")
)
Note: I have not tested this since I do not have the data set for it.

How to get the previous hour time with format in powershell?

I need to find the previous hour time with formatting with PS:
I need the below format:
"yyyy-MM-dd-HH:mm:sstt")
I can use the below code to get the date and time in this format:
(Get-Date -Format "yyyy-MM-dd-HH:mm:sstt")
2019-09-17-08:45:27AM
I need to get the previous hour time but in the above format
I know how to get the last hour time :
(Get-Date).AddHours(-1)
How can i get the previous hour time with a combination of the above
Format?
Using -f, the format operator, as shown in Ivan Mirchev's helpful answer is definitely an option, and -f is a great general-purpose formatting option to know about, for any data type.
However, in your particular case there is a simpler solution, because the .ToString() method of [datetime] instances directly accepts a format string:
(Get-Date).AddHours(-1).ToString('yyyy-MM-dd-HH:mm:sstt')
You may try using the format operator:
"{0:yyyy-MM-dd-HH:mm:sstt}" -f (get-date).AddHours(-1)
more details: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_operators?view=powershell-6#format-operator--f
Hope it helps! :)

Gnuplot, how plot the month in a title or legend?

have a new problem. Can someone help me with this?
A part of my datafile is
06-07-2013,13461,0,7464,0,
07-07-2013,14494,0,5584,0,
08-07-2013,149,13394,3412,2471,
09-07-2013,295,14058,3005,3201,
10-07-2013,194,8308,3264,4026,
11-07-2013,14,4597,3162,1945,
12-07-2013,113,4447,3009,2268,
And want to have the name of the
month and the year (in this case july 2013) in the legend or the title of the plot. How can I get first the month(value) out of the datafile and second make a text of it?
Woow, it is a beauty and almost perfect, look to the circle in the plot.
The Year is some late (lol).
http://ccvd.eu/downloads/Jul.png
I got him, the tricker was fmt = '%d-%m-%Y' in place of fmt = '%d-%m-%y'
http://ccvd.eu/downloads/Jul.png
Thank you so much!! I was for more then a day looking for the solution and now . . . YES.
In principle, to extract a certain value from a data file, you can use the stats command like shown in Gnuplot: How to load and display single numeric value from data file (requires at least version 4.6.0).
But stats does not work directly with time data using set xdata time, you need a little trick. In the using statement you must access the first column as string and format it to a time stamp with strptime.
After that you can format this time stamp with strftime and put it in the title or the legend:
stats 'file.txt' using (strptime('%d-%m-%Y', stringcolumn(1))) every ::0::0
set title strftime('%B %Y', STATS_max)
Only after calling stats you can switch to time data with set xdata time.
So a more complete script could look like
set datafile separator ','
fmt = '%d-%m-%Y'
file = 'file.txt'
stats file using (strptime(fmt, stringcolumn(1))) every ::0::0 nooutput
date = strftime('%B %Y', STATS_max)
set title 'Data of '.date
set timefmt fmt
set xdata time
plot file using 1:2 title 'again '.date

Convert date in YYYY-MM-DD in Perl?

I have search the internet for some time now but I can't seem to find the right answer (maybe there is but I don't understand it).
I have this code to read a file and get the date time (from Task Scheduler query).
File.txt holds the Task Scheduler query.
"TaskName","Next Run Time","Status"
"CheckFile","20:33:00, 17/1/2013",""
=======================================
Script to read a get the next run time value.
open (FILE, "<", $file) || print "WARN: Cannot open $file: $!";
#logLines = <FILE>;
if (#list = grep(/\b$keyword\b/, #logLines)) {
foreach(#list){$result = $_;}
my #sresult = split(/(?<="),(?=")/, $result);
$name = $sresult[0];
$name =~ tr/"//d;
$next_run = $sresult[1];
$next_run =~ tr/"//d;
print $next_run;
}
#list=();
#dFormat=();
#logLines=();
close FILE;
Output will be:
20:33:00, 17/1/2013
I want to modify the output into:
20:33:00, 2013-1-17 #note that I can do this just by splitting up and rearranging the numbers.
But the problem is, 17/1/2013 in Task Scheduler query is locale dependent. It could be in the following:
1/17/2013
17/1/2013
2013/1/17
1/17/13
17/1/13
13/1/17
1-17-2013
17-1-2013
2013-1-17
1-17-13
17-1-13
13-1-17
1.17.2013
17.1.2013
2013.1.17
1.17.13
17.1.13
13.1.17
Is there any cpan module that could do what I want? Could you give a script on how to achieve this?
Please no harsh comment. Thanks.
The following should get you the format:
use Win32::OLE::NLS qw( GetLocaleInfo GetSystemDefaultLCID LOCALE_SSHORTDATE );
say GetLocaleInfo(GetSystemDefaultLCID(), LOCALE_SSHORTDATE); # yyyy-MM-dd
You could try to find a date parser that understands that format, or you could use something like the following to create a format many parsers to understand.
my %subs = (
'yyyy' => '%Y',
...
);
my $pat = join '|', map quotemeta, sort { length($b) <=> length($a) } keys %subs;
$format =~ s{($pat)}{ $subs{$1} // $1 }eg;
I can tell you answer(algorithm) about your problem:
Once upon a time
Let's think about your problem:
You want to get date from every format.
But this is not possible, because it can be 12-11-10
Okay, now you must determine (somehow) which format is used.
If you can do that, you can rule the world.
Let's think about your problem more deeper:
First you must choose delimiter. (or not, if you don't want it)
it is possible to use something like this:
(\d{1,4})(\D)(\d{1,4})(\D)(\d{1,4})
After that, you have:
$1,$3,$5 # parts of data
$2,$4 # delimiters
I took 4 because i don't know where year can be placed.
After that, you must understand, which format you have:
dd-mm-yy
mm-dd-yy
yy-mm-dd
yy-dd-mm
You can add checks for that like days or months, but, as I said before:
12-11-10 = -9 <- not possible to determine, right?
So, you must have some external info about date format, for example:
which country
which branch of science
which family
etc
it belongs to.
If you can do that, you can (probably can) determine format and 12-11-10 = 12 nov 2010
The End
Update: see this discussion. It appears that the date format may be a regional setting based on the user who runs the task. If so, all you have to do is figure out how to get that regional setting...
As others have pointed out, there is no way of resolving the ambiguities in the potential date formats.
What I would explore is some way of querying the system with a known date and see what format it returns. For example, perhaps you could schedule a fake task at a (non-ambiguous) date far in the future, see what format that task is returned in, then later delete it.
That would be a bit of a messy solution, but perhaps there is a less kludgy way of doing something similar. Is task scheduler's date format the same as the system date format? If so, you could query a known date from the system.

MATLAB - printing graph with different output names

I have a MATLAB program that graphs some things and then outputs the graph to a file. If I run this program several times in the same directory, the file gets overwritten each time. How can I make it so the filename it outputs to changes...
I currently have this:
print -depsc myfigure
I have strings, rate and name, that I want to use, but can't get anything to work. If I can't use my strings, something random would be fine as well. Any way to do this?
Many thanks!
Name it with the current date and time:
print('-depsc2', ['prefix_' datestr(now, 30)])
run right now in PST, this creates a file called prefix_20100220T200733.eps. You can obviously change the prefix and/or the date format.
You can add current time to your file name. For example:
m=magic(10);
fh=figure, surf(m);
currenttime= datestr(now,'MMSSFFF');
print(['-f',num2str(fh)],'-depsc',['outputFileName_',currenttime,'.eps']);
This code checks if file exists, and if yes, adds a counter to its name.
filename = 'myfigure';
if exist([filename '.eps'],'file')
k=1;
while exist([filename '_' num2str(k) '.eps'], 'file')
k=k+1;
end
filename = [filename '_' num2str(k)]);
end
print('-depsc', filename);
Its simple. worked for me.
currenttime= datestr(now,'dd-mm-yy_HH:MM')
filename= ['graph' currenttime '.jpg']
print('-dpdf',filename)
Or any other file format you want to export. check print help.