Skip to content

Instantly share code, notes, and snippets.

@pohanchi
Last active December 14, 2021 15:31
Show Gist options
  • Save pohanchi/767ae63c5c88926bea2b6bda1684a278 to your computer and use it in GitHub Desktop.
Save pohanchi/767ae63c5c88926bea2b6bda1684a278 to your computer and use it in GitHub Desktop.
TWCC-CLI Tools
#put it in your remote server
screen -ls | grep longjob | awk ' { print $1 }'
export LANG=C.UTF-8
export LC_ALL=C.UTF-8
export PYTHONIOENCODING=UTF-8
alias twccmk='twccli mk ccs -itype "Pytorch" -img "pytorch-21.08-py3:latest" -gpu 1 -wait -n'
rmoccs () {
twccli ls ccs | grep Ready | awk '{ print $2; }' | while read id
do
echo "Delete container ID $id"
twccli rm ccs -s $((id)) -f
done
twccli ls ccs
}
twccls () {
twccli ls ccs
}
twccin () {
output=$(twccli ls ccs -s $1 -gssh)
cmd="ssh -o 'StrictHostKeyChecking no' $output"; eval $cmd;
}
listen() {
output=$(twccli ls ccs -s $1 -gssh)
login="ssh -o 'StrictHostKeyChecking no' $output"
com='bash listen.sh'
#mon='bash screen.sh'
logfile="log_$1"
#screenfile="mon_$1"
echo "$login $com > $logfile"
eval "$login $com > $logfile"
#eval "$login $mon > $screenfile"
result=$(cat log_$1 | grep longjob)
echo "result = $result"
if [[ "$result" == *"longjob"* ]]; then
echo "Running"
return "0"
else
echo "Finish/Error"
echo "close soon"
return "1"
fi
}
listener(){
while true
do
listen $1
decision=$?
echo "Decision=$decision";
if [[ "$decision" == "0" ]];
then
echo "wait $2 seconds"
sleep $2
else
twccrm $1
rm log_$1
break
fi
done
}
task() {
output=$(twccli ls ccs -s $1 -gssh)
login="ssh -o 'StrictHostKeyChecking no' $output"
command='$2 $1'
full_command="screen -dmS longjob $command"
echo "$login $full_command";
eval "$login $full_command";
}
twccrm () {
echo "Delete container ID $1"
twccli rm ccs -s $1 -f
twccls
}
tasker () {
aid=$(twccmk $1 | grep "CCS Site" | awk '{ print $3 }' | awk '{split($0,a,":"); print a[2]}')
echo $aid;
task $aid $2
echo "Send command to remote and run!"
echo "start Listen";
sleep 5
listener $aid $3
}
@Chung-I
Copy link

Chung-I commented Dec 14, 2021

Nice script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment