Skip to content

scripting and python

I wrapped up the linux+ and started studying for the sec+ just to realize I was incredibly bored with it. It’s not challenging what-so-ever so I hit a bit of a wall on what to do next. I’ve been putting off coding for a long time, and I think it’s time I gain some proficiency. Going forward for a bit it’s likely going to be more snippets in the direction of automation, and a bit of python. I hope to get far into API integration if I can build up a strong core here. The intention is to start building a github portfolio as well.

 

This blob is just a quicky so that I could enable vim colors on all my shells. I had also set an alias on my servers for vi=vim as well. Not much to it, but it’s a start.

Yes I log into my home servers as root.

blob below, but wordpress because wordpress doesn’t handle indents well.

#!/bin/bash


#functions needed. Just scrubs text and appends if not found.
vimcolor ()
 {
 [ ! -f ~/.vimrc ] && touch ~/.vimrc

 grep -q 'syntax on' ~/.vimrc
 if [ $? -eq 1 ] 
 then
 printf "syntax on\ncolorscheme desert\n" >> ~/.vimrc
 fi
}

vimalias ()
 {
 grep -q 'alias vi=' ~/.bashrc
 if [ $? -eq 1 ] 
 then
 printf "alias vi='vim'" >> ~/.bashrc
 fi
}
#make array
declare -a targethost
#query user, initial
printf "Enter the IP or FQDN of a target machine\n(Ctrl+C to Cancel)\n:"
read -a targethost

#create indef while loop with break when user inputs done
while :
 do 
 printf "Enter another IP or FQDN, or type...\n done\nto begin running.\n:"
 read "input"
 echo $input
 if [ $input == "done" ]; then
 break
 fi 
 targethost+=("$input")
 done

#run for loop for every value in $targethost arrray
for i in "${targethost[@]}"
do
 target=$i
 #the actual action 
 sshpass -f /home/mzimmerer/Nextcloud/Scripts/.sshauth ssh -tt root@$target "$(typeset -f); vimcolor; vimalias; dnf -y --quiet install vim"

done


exit