#!/bin/bash

# Capture the current time
current_time=$(date +"%Y-%m-%d %H:%M:%S")

# Run the sbatch command with all provided arguments
sbatch_output=$(sbatch "$@")

# Extract the job ID from the sbatch output
job_id=$(echo "$sbatch_output" | grep -oP 'Submitted batch job \K[0-9]+')

# Print the job ID and the submission time
echo "$sbatch_output"
echo "Job ID $job_id submitted at $current_time"

# Run the sacct command to get the job status
if [ -n "$job_id" ]; then
  # Wait for a short time to ensure the job is registered in the system
  sleep 1
  
  # Capture the sacct output
  sacct_output=$(sacct -j "$job_id" --format=JobID,JobName,Partition,Account,AllocCPUS,State,ExitCode)
  
  # Print the sacct output
  echo "sacct output for Job ID $job_id:"
  echo "$sacct_output"
else
  echo "Failed to retrieve job ID. sacct command not run."
fi
