|
3 | 3 | # Specify the username |
4 | 4 | username="hmai" |
5 | 5 |
|
6 | | -# Get the list of job IDs and statuses for the specified user |
7 | | -job_info=$(squeue -u $username -h -o "%i %t" | awk '{print $1, $2}') |
8 | | - |
9 | | -# Initialize a counter for running jobs |
10 | | -running_job_count=0 |
11 | | - |
12 | | -# Print the table header |
13 | | -echo "Job ID Job Status Working Directory" |
14 | | -echo "------ ---------- -----------------" |
15 | | - |
16 | | -# Loop through each line of job information |
17 | | -while read -r job_line; do |
18 | | - job_id=$(echo "$job_line" | awk '{print $1}') |
19 | | - job_status=$(echo "$job_line" | awk '{print $2}') |
20 | | - working_directory=$(scontrol show job $job_id | grep "WorkDir" | awk -F'=' '{print $2}' | tr -d ' ') |
21 | | - |
22 | | - echo "$job_id $job_status $working_directory" |
23 | | - |
24 | | - if [ "$job_status" == "R" ]; then |
25 | | - ((running_job_count++)) |
26 | | - fi |
27 | | -done <<< "$job_info" |
28 | | - |
29 | | -echo "--------------------------" |
30 | | -echo "Number of running jobs for $username: $running_job_count" |
31 | | - |
| 6 | +if [ "$1" == "-R" ]; then |
| 7 | + echo "Listing running job directories for user $username:" |
| 8 | + running_dirs_count=0 |
| 9 | + |
| 10 | + for job in $(squeue -u $username --state=R -h -o %i); do |
| 11 | + # Get the working directory for the running job |
| 12 | + working_directory=$(scontrol show job $job | grep "WorkDir" | awk -F'=' '{print $2}' | tr -d ' ') |
| 13 | + echo "Job $job: $working_directory" |
| 14 | + ((running_dirs_count++)) |
| 15 | + done |
| 16 | + |
| 17 | + echo "--------------------------" |
| 18 | + echo "Number of running directories for $username: $running_dirs_count" |
| 19 | +else |
| 20 | + # Get the list of job IDs and statuses for the specified user |
| 21 | + job_info=$(squeue -u $username -h -o "%i %t" | awk '{print $1, $2}') |
| 22 | + |
| 23 | + # Initialize a counter for running jobs |
| 24 | + running_job_count=0 |
| 25 | + |
| 26 | + # Print the table header |
| 27 | + echo "Job ID Job Status Working Directory" |
| 28 | + echo "------ ---------- -----------------" |
| 29 | + |
| 30 | + # Loop through each line of job information |
| 31 | + while read -r job_line; do |
| 32 | + job_id=$(echo "$job_line" | awk '{print $1}') |
| 33 | + job_status=$(echo "$job_line" | awk '{print $2}') |
| 34 | + working_directory=$(scontrol show job $job_id | grep "WorkDir" | awk -F'=' '{print $2}' | tr -d ' ') |
| 35 | + |
| 36 | + echo "$job_id $job_status $working_directory" |
| 37 | + |
| 38 | + if [ "$job_status" == "R" ]; then |
| 39 | + ((running_job_count++)) |
| 40 | + fi |
| 41 | + done <<< "$job_info" |
| 42 | + |
| 43 | + echo "--------------------------" |
| 44 | + echo "Number of running jobs for $username: $running_job_count" |
| 45 | +fi |
0 commit comments