run previous date script from crontab - unix

I made a small script to take take previous date as argument. The script is running fine but when running this script from crontab it takes todays date
Script
Previous_day=`date --date="-1 days" +% Y% m% d`;
./some_script -date $Previous_day ;
Some_script is script which takes date as argument provided using -date
This is solaris box
Dont know why when running from crontab it runs with argument as today's date

% is a special character in Cron, so you should escape the date parameters:
Previous_day=`date --date="-1 days" +\%Y\%m\%d;

Related

how to make a dummy job to run for 30 minutes in controlm

I have the requirement to run dummy jobs for 30 minutes and 60 minutes respectively.
I have tried with --delay 30 in command line jobs, but I did not get the expected delay.
Designating a job as type ‘dummy’ will bypass anything contained within the command line field.
You have two options to create a 30/60minute timer job.
Option a:
Make the job a command line type job and put sleep 1800 or sleep 3600 in the command line field.
Option b:
Make the job a dummy type job and put sleep 1800 or sleep 3600 in either the pre-execution or post-execution fields.
By default the sleep command operates on seconds. For windows you may want to look into using the power shell version which would be powershell.exe -command start-sleep 1800
Use _sleep over sleep instead
Another way to enable a waiting time, either before or after an OS-type Job is by using the pre-execution or post-execution command options, as appropriate.
The use of _sleep is more convenient because it is operating system independent and is provided by the Control-M/Agent, which means that you do not require an extra deployment for that functionality.

batch file Subtracting hour current time on Windows

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.

Not able to manipulate date on Unix shell script (date: illegal option -- d)

I have a requirement to add 10 days to current date and assign it to a variable. But I am getting error:
date: illegal option -- d
This is what I tried:
$> NEW_expration_DATE=$(date -d "+10 days")
Result:
date: illegal option -- d
Usage: date [-u] [+Field Descriptors]
Try this:
NEW_expration_DATE=$(gdate -d "+10 days")
It looks like you are using a POSIX shell, and that there is no way to do simple date arithmetic in here.
I found a guy who explains it and who coded something to substract dates. You may be able to adapt it for your case: https://unix.stackexchange.com/a/7220/162444
Good luck!
You can check the system with "unmane -a" and do a fine search, for example in AIX can use to get yesterday:
YESTERDAY=`TZ=aaa24 date +%Y%m%d`

Create a batch file to load a webpage when the date and time are correct

I am trying to get a webpage to load when the date and time are correct. The code I have come up with is:
#echo off
:repeat
set CurrentTime=%time:~0,2%.%time:~3,2%
set CurrentDate=%date:/=-%
echo.
echo %CurrentDate% %CurrentTime%
echo.
IF %CurrentTime% == Tue 08-04-2014 13.04 goto load
timeout /t 1 >nul
goto repeat
:load
start/MAX iexplore.exe"" "http://www.youtube.com.au"
timeout /t 6 >nul
It will work if I remove the CurrentDate and the date from the IF statement but it won't if I don't. I do need the date and time to work.
Thanks.
IF "%date% %Time%"=="Tue 08-04-2014 13.04" goto load
shoud work for you. You need to use the "quotes" to group the string as a single entity, otherwise IF has no way of telling whether the == is a part of the string to be compared or it's the comparison operator. (and that assumes that your date format is Tue 08-04-2014 and time is 13.04)
Aditionally to the solution that Magoo has posted, note that %DATE% returns the current date using the short date format that is fully and endlessly customizable by the users. One user may configure its system to return Tue 08/04/2014 and another user may choose Apr8th14. It's a complete nightmare for a BAT programmer. Even in the same computer. This is also true for the ~t modifier when expanding a variable containing a filename.
There are several solutions, google a bit to find them. The easiest in my opinion is to use WMIC
WMIC Path Win32_LocalTime Get Day,Hour,Minute,Month,Second,Year /Format:table
returns the date in a convenient way to directly parse with a FOR command.
FOR /F "skip=1 tokens=1-6" %%A IN ('WMIC Path Win32_LocalTime Get Day^,Hour^,Minute^,Month^,Second^,Year /Format:table') DO (
SET /A currentdate=%%F*10000+%%D*100+%%A
)
IF "%currentdate"=="20140408" goto load
You can also use a scheduled task if that suits the reason for you wanting to load the page.

Wrapper script to run a particular job in Control m

I have to write a wrapper script to run 3 jobs in control M if a variable is Y i.e
$EOM_1=’Y’ [incase of End of Month true]
$EOM_1=’N’ [incase of End of Month false]
i.e if $EOM_1=’Y’ run jobs like ${DirTOOLS}/WaitUnitFileExists.sh $APIS/files/tr/chqload/local/INWUSD.dat 60 05 30
Why is the wrapper script needed? You can do this with the Job Defintions within Control-M. In the DAYS field in the job scheduling defintion for the job to run the last day of the month you would put L1.
For the Job that will run all but the last day of the month you specify -L1 in the DAYS field. For the job that has to wait on a file, run the Control-M File watcher utility that will then add the condition for the job or force the job in to run.

Resources