Is there any way to create a cron expression for not running the job at all?
I though of using this expression :
0 0 0 1 1 ? 3099
...which will practically do the job as it will run on year 3099, but is there a cleaner way to do it?
If you're still looking for something robust even in the far future, try https://stackoverflow.com/a/13938099/1601531, where I suggest the use of February 31st in crontab entries which are never intended to execute.
0 0 5 31 2 ?
I needed a valid cron schedule (? syntax not working in my system) which resolves real dates, but to be effectively "never". My current best solution was to pick the most recent leap year and see what day Feb 29th fell on. Feb 29 2016 was a Monday, so the next Monday Feb 29 is currently furthest away.
0 0 29 2 1 yields the next 5 triggers as:
02/29/2044 00:00:00Z
02/29/2072 00:00:00Z
02/29/2112 00:00:00Z
02/29/2140 00:00:00Z
02/29/2168 00:00:00Z
Not perfect but it'll do.
Pick a date in the past.
That'll never happen again. Unless it's groundhog day. Just don't pick groundhog day.
I created a duplicate (click here to see) for your question, and agree with your initial proposal. After testing, it appears Quartz will never execute a cron expression with a year above 2300.
Opening your crontab file and deleting the entry would be the adequate way. Or you might as well simlink the executable that's called by the cronjob to an empty shell script.
Tell us more about your setup, then we'll see ...
Comment it out — put # sign in front of it. Very useful, especially if you're afraid you'll forget about your changes by the year 3099.
Another possibility is to make it execute dummy command, like true rm -rf /.
Related
I need to subtract, for example, 1 hour from current time in a .bat file on Windows 7.
I do it like this.
set day=%date:~0,2%
set month=%date:~-7,2%
set year=%date:~-4,4%
:: ———————————————————————–
set hour=%time:~0,2%
set /A hour= hour - 1
if %hour% lss 0 set hour=23
if %hour% lss 10 set hour=0%hour%
echo %year%-%month%-%day% %hour%:00
But the problem, it is get consistence when the subtracting results a day before on a month before. For example, this date, 2016-03-01 00:05 I get 2016-03-01 23:05. I need to get 2016-02-29 23:05
I found several batch script to subtract one day, but nothing with hours or minutes.
It's not completely Batch, but I find that there are so many exceptions and special cases, that it's not worth it re-coding everything in Batch, especially when it's been done before. I like to just invoke Powershell from a batch file, like this.
for /f "delims=" %%a in ('"powershell [DateTime]::Now.AddHours(-1).ToString('yyyy-MM-dd HH:mm')"') do echo %%a
Output will be something like: 2016-10-18 02:05
Batch files are not good in date/time operations. Spend much time with similar issues, I can recommend to use external tool such (as window port of unix 'date' command for example) and perform any operations on timestamps.
I was making a package in R and would like it to make it as a trial version for a period of 30 days .
Well my question is how to make a code self destructive depends on number of days ??
I had played with time and date package for a while where i came to know ,
Sys.Date() could give todays date , so i get forard with something below
today=Sys.Date()
a=today
b=a+1
if(a==today)
{
print(paste("today is sunday"))
if(b==today){
print(paste("today is monday"))
}
I know it is stupid work whatever i had done , my sole idea was to fix the 1st use of package as starting day ,and every day it will increment till 30 days ,when it will reach the limit it will automatically destroy using
file.remove () <- through which I can remove some file ........
May be I am clear with my ideas .
Sorry for the novice question .
Add this condition to the license. ("30 days for free, after that you'll have to pay".) and expect users to comply with this.
There is really nothing else you can do.
Well, actually you can. For example, on the first occasion your code is run, save the current date to a file in a certain location (say, "~/.datetocheck"). Then every time your code is run, check for the existence of this file, and if it exists, compare the dates. If more than 30 days have passed, give an error message:
stop("Time is over! You have to pay!")
The problem is that nothing prevents the user from simply deleting this file.
I have upgraded quantstrat package from 0.7.7(installed on Jan 7th 2013) to 0.7.8, however old code does not work properly. looks like we can not put any entry orders niether buy or sell, and only exit orders are executed. Here is the detail. Someone knows major changes in add.rule or applyStrategy function or same issue has been reported?
We set up trading rule by add.rule()
add.rule(f,'ruleSignal',arguments=list(sigcol="DoSell",sigval=TRUE,orderqty=(-1*tradeSize),osFUN='osSUS',ordertype='market',TxnFees="calcTxnFee",prefer='Open'),type='enter',label=gExitLabel)
add.rule(f,'ruleSignal',arguments=list(sigcol="DoBuy", sigval=TRUE,orderqty=tradeSize,osFUN='osBuy',ordertype='market',TxnFees="calcTxnFee",prefer='Price'),type='enter',label=gEnterLabel)
add.rule(f,'ruleSignal',arguments=list(sigcol="DoStop", sigval=TRUE,orderqty=-1*tradeSize,osFUN='osStop',ordertype='stoplimit',threshold='StopLevel',TxnFees="calcTxnFee"),type='risk',label='Stop')
The problem we had is we don't get entry signal when we run applyStrategy ...... It seems that getOrderbook has "Buy" and "Sell" .....
applyStrategy(rs, rs) only applied sell signal ........(not buy)
[1] "2010-11-18 09:00:00 ABC -65660 # 4.6"
[1] "2010-12-07 09:00:00 ABC -37509 # 5.17"
However getOrderBook() recorded "Buy", and "Sell" in order .....
at the same time order.prices were set "0", order.status "replaced" and Prefer "Price" by the system
It is hard to understand what is your problem exactly: "no entry signal", "orderbook has Buy and Sell" (whatever that means), "order.prices were set to 0" ...
I see that you are using your own order sizing functions, could it have something to do with that? You may try dropping your order sizing functions for a test, just to check if your entry orders are being executed.
Otherwise I suggest that you provide a complete example so I can run it and check.
Please be aware that quantstrat is under heavy development and that the code is patched almost on a daily basis, although the version number may not always be bumped up. So make sure that you always download the latest code.
HTH,
Jan Humme.
I am debugging a program in MacOSX,
and I need that this program thinks we are one year later than the one given by the operating system.
I cannot change the time of the operation system, because I need to run a second program concurrently with the correct time.
I could modify the code of the first program to add one year each time it gets the time from the operation system, but the code is too big to do that; I prefer not to use this solution.
I heard once that there is a command in Unix to run a program with a fake/mocked time.
Do you know about it?
I haven't tried it, but libfaketime claims to do what you need.
Quoted from the website:
As an example, we want the "date" command to report our faked time. To do so, we could use the following command line:
user#host> date
Tue Nov 23 12:01:05 CEST 2007
user#host> LD_PRELOAD=/usr/local/lib/libfaketime.so.1 FAKETIME="-15d" date
Mon Nov 8 12:01:12 CEST 2007
Assuming the lib works as advertised, you can trick your program into thinking it was running a year ahead using:
LD_PRELOAD=/usr/local/lib/libfaketime.so.1 FAKETIME="+1y" ./your_program
I'm tryin' to find a way (from a batch file) that I can use to create a scheduled task that will execute 6 months from now. I've looked all over the net, and I'll I've come across is AT and SCHTASKS that will schedule the task monthly ..
I'm looking for a solution that will execute this task every 6 months.
I know this will require some time/date manipulation .. finding the month (number of month) and then adding 6 to it; once it passes '12' it goes back to 1 etc .. Then lining those numbers up with the months name, and using SCHTASKS or AT to schedule the task.
I know how to use SCHTASKS to schedule a task from a batch file; I just need the code to find the month, add 6 to it, grab the months name in 6 months time, and put that into a variable so I can parse it into the SCHTASKS.
I hope this all makes sense.
My english is not so great.
TIA,
Greg
Thanks to everyone who replied, and offered suggestions. I slept on it, woke up with the flu, and had a brainwave. Funny how things work out. I know this is overkill, and someone will come up with a better suggestion, but here goes anyway ..
REM Grab month number and put into variable
FOR /F "TOKENS=1,2 eol=/ DELIMS=/ " %%A IN ('DATE/T') DO SET mm=%%B
REM Six months from now
set /a addmm=%mm% + 6
if %addmm% gtr 6 (set /a sixmonths=%addmm% - 12)
REM Determine month name
if %sixmonths%==1 (set monthname=JAN)
if %sixmonths%==2 (set monthname=FEB)
if %sixmonths%==3 (set monthname=MAR)
if %sixmonths%==4 (set monthname=APR)
if %sixmonths%==5 (set monthname=MAY)
if %sixmonths%==6 (set monthname=JUN)
if %sixmonths%==7 (set monthname=JUL)
if %sixmonths%==8 (set monthname=AUG)
if %sixmonths%==9 (set monthname=SEP)
if %sixmonths%==10 (set monthname=OCT)
if %sixmonths%==11 (set monthname=NOV)
if %sixmonths%==12 (set monthname=DEC)
REM Schedule Task
schtasks /create /TN TuneUpReminder /RU system /TR TuneUpReminder.bat /SC MONTHLY /M %monthname%
Why not use the Windows Scheduler?
Most of the information you need is included in this article: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/schtasks.mspx?mfr=true
You can use the monthly setting, with a value of 6 surely?
Here's a crazy idea: in case you want this script on a server (which isn't rebooted), you could write a batch file which waits for six months and then executes the given program. To wait for a specific number of seconds you could abuse the 'ping' command, like this:
ping -n %SECS% localhost > NUL
This command will effectively pause for %SECS% seconds and then return. To wait for six months, simply wait for something like (365 / 2) * 24 * 60 * 60 seconds.
Here's a little batch file which implements this idea:
#echo off
set CMD=echo Half a year elapsed
set /a SECS_IN_HALF_A_YEAR=365 / 2 * 24 * 60 * 60
loop_start:
ping -n %SECS_IN_HALF_A_YEAR% localhost > NUL
%CMD%
goto loop_start
I'm not saying it's pretty, but I thought it's a funky idea. Maybe some food for thought. :-)
you can download coreutils for windows . Then use date command like this
C:\test>gnu_date "+%Y%m%d" -d "6 months"
20110404
(it is renamed to gnu_date.exe )
I have not played with schtasks, but depending on what format of date it uses, you can change the parameters to suit schtasks
C:\test>gnu_date "+%Y-%m-%d" -d "6 months"
2011-04-04
If you need time as well
C:\test>gnu_date "+%Y-%m-%d-%H:%M:%S" -d "6 months"
2011-04-04-18:12:35
Use a for loop to save the date to a variable as desired. then pass it to schtasks for scheduling
Since Greg's answer made me cry inside, here is some array like syntax:
for /F "tokens=%sixmonths%" %%A IN ("JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC") DO set monthname=%%A
And since there’s always more than one way to skin a bat[ch]?
set /a sixmonths=%sixmonths% * 4
set months=666 JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC
setlocal ENABLEDELAYEDEXPANSION
set monthname=!months:~%sixmonths%,3!
REM Optional: setlocal DISABLEDELAYEDEXPANSION