You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

93 regels
2.6 KiB

  1. # common/.profile.d/20-functions.sh
  2. # Remove a line matched in $HOME/.ssh/known_hosts for when there are legit
  3. # host key changes.
  4. nukehost()
  5. {
  6. if [ -z "$1" ]; then
  7. echo "Usage: nukehost <hostname>"
  8. echo " Removes <hostname> from ssh known_host file."
  9. else
  10. sed -i -e "/$1/d" ~/.ssh/known_hosts
  11. fi
  12. }
  13. # Cheap copy function to make copying a file via ssh from one host
  14. # to another less painful, use pipeviewer to give some idea as to progress.
  15. ssh-copyfile()
  16. {
  17. if [ -z "$1" -o -z "$2" ]; then
  18. echo "Usage: copy source:/file/location destination:/file/location"
  19. else
  20. srchost="$(echo "$1" | awk -F: '{print $1}')"
  21. src="$(echo "$1" | awk -F: '{print $2}')"
  22. dsthost="$(echo "$2" | awk -F: '{print $1}')"
  23. dst="$(echo "$2" | awk -F: '{print $2}')"
  24. size=$(ssh "$srchost" du -hs "$src" 2> /dev/null)
  25. size=$(echo "${size}" | awk '{print $1}')
  26. echo "Copying $size to $dst"
  27. ssh "$srchost" "/bin/cat \$src" 2> /dev/null | pv -cb -N copied - | ssh "$dsthost" "/bin/cat - > \$dst" 2> /dev/null
  28. fi
  29. }
  30. # extract function to automate being lazy at extracting archives.
  31. extract()
  32. {
  33. if [ -f "$1" ]; then
  34. case ${1} in
  35. *.tar.bz2|*.tbz2|*.tbz) bunzip2 -c "$1" | tar xvf -;;
  36. *.tar.gz|*.tgz) gunzip -c "$1" | tar xvf -;;
  37. *.tz|*.tar.z) zcat "$1" | tar xvf -;;
  38. *.tar.xz|*.txz|*.tpxz) xz -d -c "$1" | tar xvf -;;
  39. *.bz2) bunzip2 "$1";;
  40. *.gz) gunzip "$1";;
  41. *.jar|*.zip) unzip "$1";;
  42. *.rar) unrar x "$1";;
  43. *.tar) tar -xvf "$1";;
  44. *.z) uncompress "$1";;
  45. *.rpm) rpm2cpio "$1" | cpio -idv;;
  46. *) echo "Unable to extract <$1> Unknown extension."
  47. esac
  48. else
  49. print "File <$1> does not exist."
  50. fi
  51. }
  52. # Tcsh compatibility so I can be a lazy bastard and paste things directly
  53. # if/when I need to.
  54. setenv()
  55. {
  56. export "$1=$2"
  57. }
  58. # Just to be lazy, set/unset the DEBUG env variable used in my scripts
  59. debug()
  60. {
  61. if [ -z "$DEBUG" ]; then
  62. if [ -z "$1" ]; then
  63. echo Setting DEBUG to "$1"
  64. setenv DEBUG "$1"
  65. else
  66. echo Setting DEBUG to default
  67. setenv DEBUG default
  68. fi
  69. else
  70. echo Unsetting DEBUG
  71. unset DEBUG
  72. fi
  73. }
  74. login_shell()
  75. {
  76. [ "$-" = "*i*" ]
  77. }
  78. # Yeah, sick of using the web browser for this crap
  79. # Use is NUM FROM TO and boom get the currency converted from goggle.
  80. cconv()
  81. {
  82. curl -L --silent\
  83. "https://www.google.com/finance/converter?a=$1&from=$2&to=$3"
  84. | grep converter_result\
  85. | perl -pe 's|[<]\w+ \w+[=]\w+[>]||g;' -e 's|[<][/]span[>]||'
  86. }