125 lines
2.6 KiB
Bash
Executable File
125 lines
2.6 KiB
Bash
Executable File
#!/bin/bash
|
||
|
||
if [[ "$1" = "-h" ]]; then
|
||
echo "utility to control tsp with menu"
|
||
exit
|
||
fi
|
||
|
||
. qolop
|
||
_qCol export _
|
||
function fkey_colorize() {
|
||
for word in $@; do
|
||
echo -ne "${_G}${word:0:1}${_Z}${word:1} "
|
||
done
|
||
echo
|
||
}
|
||
|
||
function _title() {
|
||
echo -e "${_U}${_S}======= $@ =======${_Z}"
|
||
}
|
||
|
||
function get_id() {
|
||
tsp -l
|
||
echo -e "${_Y}"
|
||
read -i "$id" -e -p "id? " id
|
||
echo -e "${_Z}"
|
||
if [[ "$id" = q ]]; then
|
||
exit
|
||
fi
|
||
}
|
||
|
||
function shuffle_jobs() {
|
||
ids=( $( tsp -l | tail -n +2 | grep queued | cut -d' ' -f1 ) )
|
||
ids_len=${#ids[@]}
|
||
for src in ${ids[@]}; do
|
||
new=${ids[$(( $RANDOM % $ids_len ))]}
|
||
if [[ $new -eq $src ]]; then
|
||
continue
|
||
fi
|
||
tsp -U "${src}-${new}"
|
||
done
|
||
}
|
||
|
||
|
||
function _del_logs() {
|
||
shopt -s nullglob
|
||
if [[ -z $( ls -1 /tmp/ | grep ^ts-out\. ) ]]; then
|
||
return
|
||
fi
|
||
ls -1 -l /tmp/ts-out.*
|
||
read -p"sure to delete logs? y/n " -n1 deletelogs
|
||
echo
|
||
if [[ "$deletelogs" = y ]]; then
|
||
find /tmp -mindepth 1 -maxdepth 1 -name 'ts-out.*' -delete -print
|
||
fi
|
||
|
||
}
|
||
|
||
function _kill_all() {
|
||
tsp -l
|
||
read -p"sure to kill all jobs (and daemon)? y/n " -n1 killtsp
|
||
echo
|
||
if [[ "$killtsp" = y ]]; then
|
||
tsp -K
|
||
fi
|
||
}
|
||
|
||
function _status() {
|
||
_title Status
|
||
echo -n "Parallel jobs (-S): "
|
||
tsp -S
|
||
echo -n "Running jobs: "
|
||
tsp -l | tail -n +2 | awk '{print $2}' | grep -c running
|
||
echo -n "Queued jobs: "
|
||
tsp -l | tail -n +2 | awk '{print $2}' | grep -c queued
|
||
echo -n "Finished jobs in success: "
|
||
tsp -l | tail -n +2 | awk '{print $2 $4}' | grep -c finished0
|
||
echo -n "Finished jobs with error: "
|
||
tsp -l | tail -n +2 | awk '{print $2 $4}' | grep finished | grep -v -c finished0
|
||
read -p "OK " foo
|
||
}
|
||
function _create_tsp_jobs() {
|
||
for i in {1..5}; do
|
||
tsp sleep 0.1
|
||
done
|
||
for i in {1..5}; do
|
||
tsp sleep 10
|
||
done
|
||
for i in {1..5}; do
|
||
tsp sleep 180
|
||
done
|
||
}
|
||
|
||
|
||
while true; do
|
||
_title "TSP"
|
||
echo '$ 'tsp $cmd $id
|
||
if [[ "$cmd" = "-c" ]]; then
|
||
eval tsp $cmd $id | less -R +G
|
||
else
|
||
eval tsp $cmd $id
|
||
fi
|
||
id=""
|
||
cmd=""
|
||
echo
|
||
fkey_colorize list console info remove kill Clear Slots shuffle DelLogs Killall @status quit
|
||
read -p"tsp " -n1 menu
|
||
if [[ "$menu" = "" ]]; then
|
||
read -t 0.1 -n1 special
|
||
if [[ -n "$special" ]]; then menu=l; fi
|
||
fi
|
||
echo
|
||
case "$menu" in
|
||
q|) break;;
|
||
l) cmd=-l;;
|
||
c|i|r|k) cmd=-"$menu"; _title "Which ID?"; get_id; ;;
|
||
C) cmd=-C; ;;
|
||
S) cmd=""; _title Current:; tsp -S; read -p "new? " -i 1 -e num; tsp -S $num; ;;
|
||
K) _kill_all ;;
|
||
D) _del_logs ;;
|
||
s) shuffle_jobs ;;
|
||
@) _status ;;
|
||
*) cmd=-l;;
|
||
esac
|
||
done
|