Get just the staus of autosys (main) job/box - unix

I have a main autosys box (first_start_main_job)that has 2 different sub box.
When I enter autorep -j first_start_main_job -d I get something like:
JOb Name | Last Start | Last Run | ST | RUN | Pri/Xtx
first_start_main_job | some_time | some_time | SU | some_text
first_start_sub_job | some_time | some_time | SU | some_text
second_start_sub_job | some_time | some_time | SU | some_text
I just want ST(status) of first_start_main_job and store that in a variable.
Please let me know how to accomplish this.
Thanks in advance..

Use the print level switch -L, with level 0, (zero) to list only the outermost box. Then use your favorite script tool to get and store the ST value.
For example:
autorep -J main_job_box -d -L0
man autorep from a AutoSys command prompt will give you more information if you need it.

Just adding up to above posted answer.
To get the Status of Job in a variable we can filter out the status using awk.
e.g.
autorep -J first_start_main_job -d -L0 | awk '/SU /{print $6}'
It will check for the first line and if it contains "SU ", than the status will be printed.

Related

Most frequently used commands during the last x months

I know how to get the most used shell commands in zsh with
history 1 | awk '{$1="";print substr($0,2)}' | sort | uniq -c | sort -n | tail -n 20
but is there a way to restrict myself to let's say the last two or three months?
I need this because I would like to create aliases for the commands I am currently using most.
history in zsh have several flags to show date and time stamp. For this to work, you have to add setopt extended_history to your .zshrc file.
If you have extended_history enabled, history -i will show full time-date stamps in ISO8601 `yyyy-mm-dd hh:mm' format. Dates in this format can be compared as strings. So just change your awk script and use it to select only lines after some date.
history -i 1 | awk '{ if ($2 >= "2020-05-01") { $1=$2=$3="";print $0; } }' | sort | uniq -c | sort -n -r | head -n 20
Be aware that if you have HIST_IGNORE_ALL_DUPS or HIST_IGNORE_DUPS options enabled, this will not work as intended.
You can also use date command to get older date automatically.

Unix - Using pipe inside watch command (Count connections groupped by state)

I am trying to count the amount of connections while groupping them by their 'state'.
This command achieve that goal :
netstat -ant | awk '{ print $6}' | sort | uniq -c
which provide an output that looks like that :
4 CLOSE_WAIT
1 established)
127 ESTABLISHED
1 Foreign
2 LAST_ACK
39 LISTEN
9 TIME_WAIT
I am trying to combine my command with the watch command like that :
watch -n 1 "netstat -ant | awk '{ print $6}' | sort | uniq -c"
But, the output is just of the netstat -ant command (and not the last output of the pipe).
How can I use that complex command with watch ?
This works:
watch -n1 "netstat -ant | awk '{ print \$6}' | sort | uniq -c"
You're passing a double quoted string that happens to contain single quotes. Inside a double quoted string, $s meant as literal $s must be escaped ($6 => \$6).
When you don't escape it, watch will likely receive
"netstat -ant | awk '{ print }' | sort | uniq -c"
(as $6 is likely to be unset), which would explain the output you're getting (awk '{ print }' in a pipeline is essentially a no-op, like cat).

long running process id based on grep condition and send mail

ps -eaf | LaunchKTRProcess | grep -v grep
this command will give me , full details of process, and i have to manually check his Running time and kill the process.
This
ps -e | sed 1d | egrep -v '^ *[^ ]+ +[^ ]+ +([^ ]|00:0.):'
gives the ps of all processes which run for more than ten minutes (I use sed 1d to remove the ps header line because not every ps has an option to suppress it); you can filter the output based on further conditions. Then
| awk '{print $1}'
extracts the PIDs (1st column).

cleartool describe -ahlink -all filename

I am doing a describe on a file:
ct desc -ahlink -all 5.txt
5.txt##/main/52
Hyperlinks:
Merge <- /vobs/TESTVOB/5.txt##/main/test_branch/1
Merge <- /vobs/TESTVOB/5.txt##/main/test_branch/2
Is there a way in clearcase using -fmt something to get the last hyperlink from the describe command without using unix commands to achieve it?
If not can someone suggest me the appropriate unix command to get the desired output?
I tried this command:
ct desc -ahlink -all 5.txt | grep Merge | cut -d "-" -f2
and this gives me:
/vobs/TESTVOB/5.txt##/main/test_branch/1
/vobs/TESTVOB/5.txt##/main/test_branch/2
I only want:
/vobs/TESTVOB/5.txt##/main/test_branch/2
Thanks in advance for your help
I don't know of a native way to get that last hyperlink.
So using a unix command like tail should be enough:
ct desc -ahlink -all 5.txt | grep Merge | tail -1 | cut -d "-" -f2

sorting ls-l owners in Unix

I want to sort the owners in alphabetical order from a call to ls -l and cannot figure out a way to do it. I know something like ls-l | sort would sort the file name but how do i sort the owners in order?
The owner is the third field, so use -k 3:
ls -l | sort -k 3
You can extend this idea to sorting based on other fields, and you can have multiple -k options. For instance, maybe you want to sort by owner, and then size in descending order:
ls -l | sort -k 3,3 -k 5rn
I am not sure if you want only the owners or the whole information sorted by owner. In the former case superfo's solution is almost correct.
Additionally you need to remove repeating white spaces from ls's output with tr because otherwise cut that uses them as a delimiter won't work in all directories.*
So in the end you get this:
ls -l | tr -s ' ' | cut -d ' ' -f 3 | sort | uniq
*Some directories have a two digit value in the second field and all other lines with a single digit get an additional whitespace to preserve the layout.
How about ...
ls -l | cut -d ' ' -f 3 | sort | uniq
Try this:
ls -l | awk '{print $3, $4, $8}' | sort
It will print the user name, the group name and the file name. (File name cannot contain spaces)
ls -l | awk '{print $3, $4, $0}' | sort
This will print the user name, group name and the full ls -l output, sorted by the user name first, then the group name, then what ls -l prints first

Resources