You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Unix命令获取Autosys指定日期时段的调度作业列表?

Querying Autosys Jobs by Scheduled Time (and Identifying Overdue Jobs)

Let's break down your two core requirements: fetching jobs scheduled in a specific time window, and finding jobs that were scheduled over 2 hours ago but haven't started yet. Autosys provides command-line tools like autorep and jobquery that we can combine with standard Unix utilities to get exactly the data you need.

1. Get Jobs Scheduled in a Specific Time Window (e.g., 22-Mar-2018 08:00-10:00)

First, we'll pull job scheduling details with autorep, then filter results to match your target time range. Here's a step-by-step approach:

Step 1: Convert your time window to Unix timestamps

Unix timestamps (seconds since the epoch) make time comparisons straightforward. Define your start and end times first:

# Replace with your target date/time (format: YYYY-MM-DD HH:MM:SS)
start_time="2018-03-22 08:00:00"
end_time="2018-03-22 10:00:00"

start_ts=$(date -d "$start_time" +%s)
end_ts=$(date -d "$end_time" +%s)

Step 2: Fetch and filter matching jobs

Use autorep to get job names and their scheduled times, then loop through to check if each job falls within your window. Adjust the date parsing based on your Autosys environment's date format (common formats are DD-MMM-YYYY HH:MM:SS or MM/DD/YYYY HH:MM:SS):

For DD-MMM-YYYY format (e.g., 22-Mar-2018 08:30:00):

autorep -J ALL -s | awk '/^Job Name:/ {job=$3} /^Sched Time:/ {sched=$3" "$4; print job, sched}' | while read job sched_date sched_time; do
    # Convert Autosys date to a format `date` can parse
    sched_ts=$(date -d "$sched_date $sched_time" +%s)
    # Check if scheduled time is within your target window
    if [ $sched_ts -ge $start_ts ] && [ $sched_ts -le $end_ts ]; then
        echo "Job: $job | Scheduled at: $sched_date $sched_time"
    fi
done

For MM/DD/YYYY format (e.g., 03/22/2018 08:30:00):

Modify the sched_ts line to swap month and day for correct parsing:

sched_ts=$(date -d "$(echo $sched_date | awk -F/ '{print $2"/"$1"/"$3}') $sched_time" +%s)

2. Find Jobs Scheduled Over 2 Hours Ago That Haven't Started

We need to target jobs in SCHEDULED or READY status (not yet initiated) where their scheduled time is more than 2 hours in the past. Here's how to do this:

Step 1: Calculate the timestamp for 2 hours ago

current_ts=$(date +%s)
two_hours_ago=$((current_ts - 7200)) # 7200 seconds = 2 hours

Step 2: Identify overdue jobs

Use autorep to get job status and scheduled time, then filter for jobs that meet the overdue criteria:

autorep -J ALL -s | awk '/^Job Name:/ {job=$3} /^Status:/ {status=$3} /^Sched Time:/ {sched=$3" "$4; print job, status, sched}' | while read job status sched_date sched_time; do
    sched_ts=$(date -d "$sched_date $sched_time" +%s)
    # Check if job is still waiting and scheduled time is over 2 hours ago
    if [ "$status" = "SCHEDULED" ] || [ "$status" = "READY" ]; then
        if [ $sched_ts -le $two_hours_ago ]; then
            echo "Overdue Job: $job | Status: $status | Scheduled at: $sched_date $sched_time"
        fi
    fi
done

Alternative: Use jobquery for more targeted results

If your Autosys environment supports jobquery, you can simplify the command to directly filter by status:

jobquery -s SCHEDULED,READY -f job_name,sched_time | while read job sched; do
    sched_ts=$(date -d "$sched" +%s)
    if [ $sched_ts -le $two_hours_ago ]; then
        echo "Overdue Job: $job | Scheduled at: $sched"
    fi
done

Key Notes

  • Permissions: Ensure you have the necessary Autosys permissions to run autorep or jobquery (usually requires read access to the job database).
  • Date Format: Always verify your Autosys instance's date format (check autorep -J <any_job> -s output) and adjust the date parsing commands accordingly.
  • Complex Schedules: For jobs with dependencies, calendars, or conditional schedules, use autorep -J <job> -d to review the full job definition and confirm the expected run time.

内容的提问来源于stack exchange,提问作者vidya lakshmipathy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 12:32:03