Date for the next run of the job in Autosys - autosys

I have a job which runs on business days (MON-FRI). I need the date for the next run of the job. so Suppose if Job is running on Monday I need date of Tuesday or if Job is running on Friday I need date of Monday.

The job_depends command will let you see the future schedule for a job. Use the -J parameter with the job name, the -t parameter to denote time dependency, and the -F parameter with a current datetime stamp to find the next run in the future.

You may use Job Forecast report by using -t and -F combination.
job_depends -t -w -J <JOB_NAME> -F "03/29/2017" -l0
Note that this will work only for Jobs which have Date Condition. You may use -l0 if only looking for top level box.
Job Forecast Report
From: 03/29/2017 00:00:00 To: Infinity
Job Name Next Start Atomic Start Conditions
______________________________ _______________ _______________________
JOB_NAME 03/29/2017 20:40:00 -------

Related

Overrunning User Process Monitoring at Unix over a period of Time

I am new to Administration front. I have a requirement :
Identify the user processes (have a list of users who submits the process) which are still active and which have been submitted 3/4 days ago.
My Approach on this:
Have a text file with list of users.
Loop and find the current processes spawned by the users and store it a file.
Substitute a date variable with the format and grep.
However, I am stuck how to get : Submitted 3/4 days ago. With my code its equating to a day.
#!/bin/sh
rm -f psinfo.txt
rm -f psinfo_backdated.txt
for i in `cat user.lst `;
do
ps -ef | grep "$i" >> psinfo.txt
done
grep `date -d'2 day ago' +%b%d` psinfo.txt > psinfo_backdated.txt
I really need your comments and answer on this Gurus.
If some can tell if we can do grep of date range from a file like Less
than Apr27 format. I can make my script work. Waiting for the guru's
to respond on this.
A time format like Apr27 is not suitable for the task, also because it doesn't contain the year, which is necessary at the start of a year. Fortunately, there is a much better format for the start time of a process. Replace
ps -ef | grep "$i" >> psinfo.txt
with
ps -oetime=ELAPSED_TIME -ouser,pid,ppid,cpu,tty,time,args -u$i >>psinfo.txt
(you might want to drop fields you don't need from the second -o…). The time since start is then represented in the form
[[days-]hours:]minutes:seconds
- this you can easily filter with awk, e. g. to get processes started 3 or more days ago:
awk '{ if ($1~/-/ && int($1)>2) print }' psinfo.txt >psinfo_backdated.txt

Last Month Date in Solaris CSH script

As pre requirement, I need to fetch last month date in Unix (solaris) csh.
set Lmit_Date=`date --date='1 month ago' +%Y%m%d`
above command will fetch last month date and working fine in Linux server. But our server is Solaris and mentioned command is not working.
Please can anyone suggest how I can fetch the last month date
The issue is due to the fact you are using a GNU date extension. --date is non standard.
Moreover, due to the fact month lengths are variable, the date displayed by GNU date might be unexpected, to say the least...
For example today is March 31 but "last month" date was March the 2nd according to GNU date:
$ date +%Y%m%d
20160331
$ date --date='1 month ago' +%Y%m%d
20160302
If you still want to either use GNU date on Solaris or find some workarounds, have a look to these replies:
https://stackoverflow.com/a/23507108/211665 and https://stackoverflow.com/a/17817087/211665
You should be able to compile coreutils for your solaris platform, which will provide you with the right date utility. But as coreutils overwrites core utilities as the name says, you may want to install this into a custom path and select the right date command through your special path, say "/opt/coreutils/bin/date".
The other method would be to calculate last month with a symbolic date output split
eval `date +"set YEAR=%Y; set MONTH=%m ;set DAY=%d"`
Now you can operate on "$YEAR", "$MONTH" and "$DAY". For example
let 'MONTH--'
if [ "$MONTH" -eq 0 ]; then MONTH=12; let 'YEAR--'; fi
set Lmit_Date=`date --date "$MONTH$DAY0000$YEAR" +"%Y%m%d"`
kind of. (I'm used to bash so I don't know if let is available here. But there are some other methods to shell calculations. There might be another keyword for csh).
Also you need to take care for number of days per month with the $DAY parameter.
function last_day {
y=`echo $1 | cut -f1 -d "-"`
m=`echo $1 | cut -f2 -d "-"`
d=`cal ${m} ${y} | nawk 'NF{A=$NF}END{print A}'`
echo "$y $m $d" | nawk '{printf("%s-%02d-%02d",$1,$2,$3);}'
} # last_day
last_day 2023-01-01
Will give you: 2023-01-31 in non-GNU Solaris.

Convert date string to unix timestamp without "date -d" in a shell script

I've been bashing my head into the wall for some time on this one.
I have a date string in my (ksh) script. It's not the current time, it's some arbitrary time.
How can I convert that date string into a Unix timestamp? I'm working on SunOS 5.10 and AIX, which don't have the date -d option, nor the MacOS date -j -f options.
I only need to do this conversion in one place in my code, so ideally I'd like to do it in one line, but if I have to create a function then so be it
I've messed around with Python and Perl to achieve this in one line. Python came the closest, but I couldn't get it to account for time zone, which I would really like. Any help would be much appreciated.
I lost whatever I had been trying to do with Python earlier, but looking back at it I've found a solution:
python -c 'import datetime, time;print time.mktime(datetime.datetime.strptime("08/22/2014/16", "%m/%d/%Y/%H").timetuple())'
This particular command outputs 1408737600, which is 4pm on August 22 2014 on the east coast.

How to reset number of retrys on Autosys job

I have a list of jobs that have number of retrys set on them (in jil definition). When I get the job status, I see the number of retrys (in this case 12). I am trying to find a way to reset that:
->autorep -J XXXXX%
Job Name Last Start Last End ST Run/Ntry Pri/Xit
XXXXXX 03/19/2014 14:27:38 03/19/2014 14:56:07 SU 146461/12 0
number of retries could be set on a job level:
look for n_retrys: in output of command autorep -J XXXXX% -q
or it could be on server level:
grep -i MaxRestartTrys config.$AUTOSERV
MaxRestartTrys=10
the third option is that the job was triggered manualy multiple times.

shell script for sleeping 1 week

Can anyone give me the script for 'sleep a job for entire week' as a shell command.
Before sleeping in every run it should calculate the next week's date and time.
I found something which was bit useful
startTime=$(date +%s)
endTime=$(date -d "next week" +%s)
timeToWait=$(($endTime- $startTime)) sleep $timeToWait
date -d "next week"
is a different way to say
date -d "7 days"
This means "seven days from now", which is not the start of the next week and is also probably not what you want. If it is what you want and you are using GNU sleep, you can just issue this command:
sleep 7d
to have your script sleep for seven days. If you are not using GNU sleep, then you will have to convert the seven day interval to seconds:
sleep 604800
If you want the start of the next week, then this might be of help in ksh, or even in bash:
let time=`date -d "next monday" +%s`-`date +%s`
sleep $time
That said, I think that you are using the wrong tool for this job. Having a script sleep for seven days is quite impractical - any number of things could happen in the mean time, from the system rebooting to the shell process being killed.
You should look at crond and crontab, atd and at or even at a more modern cron variant/supplement, such as frcon or anacron.
May I ask why do you require a 1 week sleep?
I ask because if you want a process to wait for a week and then retry/ do something, cron job may be better. For 2 reasons -->
1) Save resources
2) If for some reason your system has to be restarted/ goes down - your shell script will stop and whatever you were waiting for will not happen.
Whereas a cron job will run exactly when you want it to run saving you from such a scenario. Some useful examples are in the link below
http://www.thegeekstuff.com/2009/06/15-practical-crontab-examples/
I learned of this because I experienced it myself! :)
coreutils sleep supports the d postfix so:
sleep 7d
Will sleep 7 days.
I warned against a single long wait, and I would not do this with a waittime of 1 week.
But I have used variations of this in the past:
waittime=
interval=
: ${waittime:?specify wait time in seconds}
: ${interval:?specify interval in seconds}
t0=SECONDS
target=$(( t0 + waittime ))
until
(( SECONDS > target ))
do
sleep $interval
done

Resources