summaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
authorxiubuzhe <xiubuzhe@sina.com>2023-10-17 00:47:21 +0800
committerxiubuzhe <xiubuzhe@sina.com>2023-10-17 00:47:21 +0800
commitb89a492b6aab2245380958bac738f1de26e3c803 (patch)
treef513cd2064da8bce725c9e2ae5a3db163a10739e /sbin
parent6cb42d6b8d889a832c19b6e0f58d29af78009d99 (diff)
downloadsunhpc-b89a492b6aab2245380958bac738f1de26e3c803.tar.gz
sunhpc-b89a492b6aab2245380958bac738f1de26e3c803.tar.bz2
sunhpc-b89a492b6aab2245380958bac738f1de26e3c803.zip
fix bash-completion
Diffstat (limited to 'sbin')
-rwxr-xr-xsbin/check-port46
-rw-r--r--sbin/sunhpc-completion-backup49
2 files changed, 46 insertions, 49 deletions
diff --git a/sbin/check-port b/sbin/check-port
new file mode 100755
index 0000000..34564a9
--- /dev/null
+++ b/sbin/check-port
@@ -0,0 +1,46 @@
+#!/opt/sunpy3/bin/python3
+
+import os
+import sys
+import socket
+import sunhpc.invoke
+
+class App(sunhpc.core.app.Application):
+
+ def __init__(self, argv):
+ sunhpc.core.app.Application.__init__(self,argv)
+
+ self.usage_name = 'Check Port'
+ self.usage_version = '4.2'
+ self.node_name = 'localhost'
+ self.port_num = 5901
+
+ nodehelp = '(nodename default=%s)' % self.node_name
+ porthelp = '(port number default=%d)' % (self.port_num)
+ self.getopt.l.extend([ ('node=',nodehelp),('port=',porthelp) ])
+ self.getopt.s.extend([('n:',nodehelp),('p:',porthelp)])
+
+ def parseArg(self, c):
+ sunhpc.core.app.Application.parseArg(self,c)
+
+ key, val = c
+ if key in ('--port'):
+ self.port_num = int(val)
+ elif key in ('--node'):
+ self.node_name = val
+
+ def run(self):
+ s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
+ try:
+ s.connect((self.node_name,self.port_num))
+ except:
+ print ('Port(%s) is closed' % self.port_num)
+ sys.exit(1)
+
+ print ('Port(%s) is open' % self.port_num)
+ s.close()
+ sys.exit(0)
+
+app = App(sys.argv)
+app.parseArgs()
+app.run()
diff --git a/sbin/sunhpc-completion-backup b/sbin/sunhpc-completion-backup
deleted file mode 100644
index 8eb4f1e..0000000
--- a/sbin/sunhpc-completion-backup
+++ /dev/null
@@ -1,49 +0,0 @@
-# sunhpc(1) completion
-
-_sunhpc_array_delete_at()
-{
- eval "local ARRAY=(\"\${$1[@]}\")"
- local i
- local tmp=()
- local lower=$2
- local upper=${3:-$lower}
-
- for i in "${!ARRAY[@]}"; do
- if [[ "$i" -lt "$2" || "$i" -gt "${3-$2}" ]]; then
- tmp=("${tmp[@]}" "${ARRAY[$i]}")
- fi
- done
- eval "$1=(\"\${tmp[@]}\")"
-}
-
-_sunhpc()
-{
- local cur prev words cword i output
- _init_completion || return
-
- _sunhpc_array_delete_at words $((cword+1)) ${#words[@]}
- _sunhpc_array_delete_at words 0
-
- for i in ${!words[@]}; do
- words[i]="$(printf '%s' "${words[i]}" | xargs printf '%s\n' 2>/dev/null || true)"
- done
-
- if [[ "$cur" =~ ^[[:space:]]+ ]]; then
- cur=''
- fi
-
- output="$(sunhpc report completion ${words[@]} 2>/dev/null)"
-
- if [ $? = 65 ]; then
- compopt -o default
- COMPREPLY=()
- return 0
- fi
-
- local IFS=$'\n'
- COMPREPLY=( $( compgen -W '$output' -- $cur ) )
-
-} &&
-complete -F _sunhpc sunhpc
-
-# ex: ts=4 sw=4 et filetype=sh