Run ssh commands remotely for one or many or a list of servers

single:

ssh -o “StrictHostKeyChecking no”  -t ${server} ‘sudo sed -ibak -e ‘s#https://oldchef.server.com/#https://newchef.server.com/#g’ /etc/chef/client.rb’

many:

for server in server001 server002 server007; do echo ${server} & ssh -o “StrictHostKeyChecking no”  -t ${server} ‘sudo sed -ibak -e ‘s#https://oldchef.server.com/#https://newchef.server.com/#g’ /etc/chef/client.rb’ ; done

list:

for server in `cat nodelist.txt`; do echo ${server} & ssh -o “StrictHostKeyChecking no”  -t ${server} ‘sudo sed -ibak -e ‘s#https://oldchef.server.com/#https://newchef.server.com/#g’ /etc/chef/client.rb’ ; done

where nodelist.txt is like:

server001

server002

server003

server004

server005

server006

server007

Add user and password to NGINX

openssl passwd -apr1

Enter password you want twice when prompted, it will generate an apr1 encrypted password

Add:

username:$apr1encryptedpassword

vi /etc/nginx/htpasswd

service nginx restart

SCOTT911:$apr1$MlStQ7sB$j0KTSvgohgERT54UeSrkZBas/

Comskip commercial skipping on plex

Plex doesn’t seem to install comskip on linux by default. Although it says it uses it, it’s not in the tarball so nothing actually happens. I guess it assumes you’ve figured it out on your own(?).

Install comskip:

Dependencies:

apt-get install -y autoconf libtool git build-essential libargtable2-dev libavformat-dev libsdl1.2-dev

sudo su –

git clone git://github.com/erikkaashoek/Comskip

cd Comskip

./autogen.sh

./configure

make

make install

Auto-skip *should* work now if you set it up in the DVR settings, existing recordings won’t have commercials skipped.

Manual commercial scans (i.e. go fix my existing recordings!):

cd to your recording

comskip –ini=/usr/lib/plexmediaserver/Resources/comskip.ini MyRecording.ts

and wait.

it makes the edl and txt files for Plex to skip commercials, but does not modify the original file in any way

Or, go hit your entire DVR directory recursively:

Read more ›

Make iTerm 2 highlight all errors all the time

This helps when you have to chase down stupid stuff all day, every day by highlighting the typical offenders:

Launch iTerm2
Go to iTerm2 – Preferences – Profiles – Advanced – Triggers – Edit
Click +

In the Regex, type:   (error|ERROR|Error)
Action: Highlight Text
Pick a color, Pick a background color that stand out for you
Check the Instant box
Close back out

I have:
(Fail|FAIL|fail)
(Differ|DIFFER|differ)
(Insufficient|INSUFFICIENT|insufficient)
(Access|ACCESS|access)
(Denied|DENIED|denied)
(Error|ERROR|error)

 

Sorting out (and finding!) connection resets on Linux:

Sorting out connection resets:

tcpdump -nn -v ‘tcp[tcpflags] & (tcp-rst) != 0’

or

tcpdump -ilo -nn -v ‘tcp[tcpflags] & (tcp-rst) != 0’

-n is to stop resolving DNS names

-nn is to stop resolving DNS names AND port numbers to names

This is really useful when an app is logging connection resets, but not telling you what it is trying to connect to in the first place.

Converting a Scratch game to an Android app

  1. Go to: https://scratch.mit.edu/ create an account
  2. (Make your game, I’ll wait)
  3. Export to Android: Log into scratch, copy the project ID from the URL
  4. Go to: Phosphorus.github.io
  5. Put the project ID that you got above into the field provided.
  6. Click “Package Project”
  7. Copy the generated URL, keep it somewhere safe
  8. Go to https://www.appsgeyser.com/ (Set up account)
  9. Click “Create Now”
  10. Choose “Website” and paste in the generated URL for your project from the phosphorus site above.
  11. Name your app
  12. Choose/Upload an icon
  13. Add a description if you want, but to test, this is unnecessary
  14. Click Download on the right side, (preview may or may not work, don’t worry if it won’t preview)
  15. It will download a .apk file, this needs to get loaded onto your android device, Dropbox or Seafile are the easiest, USB transfers work too.
  16. Copy the .apk file into Seafile/Dropbox/USB
  17. Open Seafile/Dropbox on the android and find the .apk file
  18. Touch it to download it
  19. Touch install when prompted (You may need to enable “Install from unknown sources” and try again)
Open the game on Android and test
Note that since it is Android, and scratch has no idea that it will become a touch app, you have to use things like “Follow Mouse” and “Click” or “Right Click” in addition to regular collision detection.
Make the sprite follow the mouse/touch: https://wiki.scratch.mit.edu/wiki/Making_a_Sprite_Follow_the_Mouse

bash tip: collapse or parse a big text doc into individual sorted words from columns

Start with list.txt like:

server7858   server7858   server7858   server7858   server7861   server7860   server8310   server8310   server7863   server8311

server7859   server7859   server7859   server7859   server8781   server8676   server8677   server8677   server8679   server8782

Which has duplicates and long lines and crap. Run this:

rm list2.txt

rm list3.txt

for word in `cat list.txt`; do echo $word ; done |sort |uniq >> list2.txt

sed -ibak -e ‘s/ //g’ list2.txt

cat list2.txt |sort|uniq > list3.txt

vi list3.txt

ta da!

if you need word counts and such, pipe it through wc before running uniq

more metadata, this one is hard to find:

bash

list

word

parse

parsing

text

columns

sorting

collapse

words

shell

script

split

line

lines

grep

Microsoft Visual Code won’t start on CentOS 7/KDE

sudo cp /usr/lib64/libxcb.so.1 /usr/share/code/ libxcb.so.1

cd  /usr/share/code/

sudo sed -ibak -e ‘s/BIG-REQUESTS/_IG-REQUESTS/g’  libxcb.so.1

Had the exact same problem with Atom and this worked for that too.

Bash case switches

if [[ ${TAG_VALUE}XXX == “XXX” ]]; then

echo “TAG_VALUE was blank, exiting!”

exit

fi

case ${TAG_VALUE} in

1)

echo ‘I am the first box’

;;

2)

echo ‘I am the second box’

;;

3)

echo ‘I am the third box’

;;

4)

echo ‘I am the fourth box’

;;

5)

echo ‘I am the fifth box’

;;

*)

echo ‘I am another box higher than 5’

;;

esac

Reading tags from CLI or bash in ec2 instances

# To read the Name tag:

TAG_NAME=”Name”

INSTANCE_ID=”`./ec2-metadata -i | cut -f 2 -d ” ” `”

REGION=”`././ec2-metadata -z | cut -f 2 -d ” ” `”

REGION=${REGION%?}

TAG_VALUE=”`aws ec2 describe-tags –filters “Name=resource-id,Values=$INSTANCE_ID” “Name=key,Values=$TAG_NAME” –region $REGION –output=text | cut -f5`”

Gives:

set |grep TAG_VALUE

TAG_VALUE=’brad test box’

# To see ALL tags to see WTF: (use region from above)

aws ec2 describe-tags –region us-east-1 –output=text

# To read the Created-by custom tag:

TAG_NAME=”created-by”

INSTANCE_ID=”`./ec2-metadata -i | cut -f 2 -d ” ” `”

REGION=”`././ec2-metadata -z | cut -f 2 -d ” ” `”

REGION=${REGION%?}

TAG_VALUE=”`aws ec2 describe-tags –filters “Name=resource-id,Values=$INSTANCE_ID” “Name=key,Values=$TAG_NAME” –region $REGION –output=text | cut -f5`”

set |grep TAG_VALUE

TAG_VALUE=test-kitchen

# To read the nifi-node-num custom tag:

TAG_NAME=”nifi-node-num”

echo “TAG_NAME is: ” ${TAG_NAME}

INSTANCE_ID=”`./ec2-metadata -i | cut -f 2 -d ” ” `”

echo “INSTANCE_ID is: ” ${INSTANCE_ID}

REGION=”`././ec2-metadata -z | cut -f 2 -d ” ” `”

REGION=${REGION%?}

echo “REGION is: ” ${REGION}

TAG_VALUE=”`aws ec2 describe-tags –filters “Name=resource-id,Values=$INSTANCE_ID” “Name=key,Values=$TAG_NAME” –region $REGION –output=text | cut -f5`”

echo “TAG_VALUE is: ” ${TAG_VALUE}

# You need the EC2 Metadata binary for the above to work

wget http://s3.amazonaws.com/ec2metadata/ec2-metadata

chmod u+x ec2-metadata

./ec2-metadata –help

Top