Migrate pwgen.py to bash
This commit is contained in:
parent
47afa44ed3
commit
aece66a1d1
@ -17,3 +17,17 @@ function kres {
|
||||
kubectl get $1 -A $_O | grep "$_D*$2$_D*\s\+$_D*$3$_D*"
|
||||
fi
|
||||
}
|
||||
|
||||
function pwgen {
|
||||
local _LEN=$1
|
||||
case $_LEN in
|
||||
''|*[!0-9]*)
|
||||
echo "Enter a valid number" > /dev/stderr
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
LC_ALL=C tr -dc '[:graph:]' </dev/urandom | head -c $_LEN
|
||||
if [ -t 1 ]; then
|
||||
echo
|
||||
fi
|
||||
}
|
||||
|
@ -1,32 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import string;
|
||||
import random;
|
||||
|
||||
import os;
|
||||
import sys;
|
||||
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
sys.exit('Usage: ' + os.path.basename(__file__) + ' length');
|
||||
|
||||
l = sys.argv[1];
|
||||
|
||||
if not l.isdigit():
|
||||
sys.exit('"' + l + '" is not a valid length.');
|
||||
|
||||
# cast l into intergers
|
||||
l = int(l);
|
||||
|
||||
# define the character set
|
||||
charSet = string.ascii_letters + string.digits;
|
||||
|
||||
# generate stack
|
||||
out_stack = ''.join(random.choice(charSet) for x in range(l));
|
||||
|
||||
# Am I being piped?
|
||||
if sys.stdout.isatty():
|
||||
print(out_stack);
|
||||
else:
|
||||
sys.stdout.write(out_stack);
|
||||
|
Loading…
Reference in New Issue
Block a user