Skip to content

Instantly share code, notes, and snippets.

@heiwa4126
heiwa4126 / baa_ba.py
Created May 26, 2021 04:28
baa + ba = abb
#!/usr/bin/env python3
"""
baa + ba = abb
https://twitter.com/koujounodenki/status/1397188516044541955
"""
for b in range(1, 10):
for a in range(0, 10):
x = b * 100 + a * 10 + a
y = b * 10 + a
@heiwa4126
heiwa4126 / update_rhel7.sh
Created May 12, 2021 08:36
RHEL7で、手動アップデートの際に使ってるスクリプト。~/bin/update.shに置いてる。
#!/usr/bin/bash -e
# for RHEL7
sudo -i sh -c "\
yum update --downloadonly -y\
"
echo "Continue? (Enter or Ctrl+C)" ; read Wait
sudo -i sh -c "\
yum update -y ;\
@heiwa4126
heiwa4126 / update_ubuntu.sh
Last active May 12, 2021 01:26
Ubuntu 18.04LTSで、手動アップデートの際に使ってるスクリプト。~/bin/update.shに置いてる。
#!/bin/bash -e
sudo -i sh -c "\
apt-get update ;\
apt-get -uyd dist-upgrade\
"
echo "Continue? (Enter or Ctrl+C)" ; read Wait
sudo -i sh -c "\
apt-get -uy dist-upgrade ;\
@heiwa4126
heiwa4126 / as_admin.bat
Created March 31, 2021 06:42
.batをダブルクリックで管理者権限で実行する。ダイアログはでるけど「右クリックで管理者権限で実行」よりは全然楽。もとは https://4thsight.xyz/13971 。空白を含むパスで実行すると死ぬバグを直した。
@echo off
cd /d "%~dp0"
for /f "tokens=3 delims=\ " %%i in ('whoami /groups^|find "Mandatory"') do set LEVEL=%%i
if NOT "%LEVEL%"=="High" (
powershell.exe -NoProfile -ExecutionPolicy RemoteSigned -Command "Start-Process \"%~f0\" -Verb runas"
exit
)
rem これ以降に、実行したい処理を記述します
@heiwa4126
heiwa4126 / pexpect_ex1.yml
Created March 24, 2021 07:43
andibleのexpectモジュールの練習。微妙なコツがいるのがめんどくさい
# andibleのexpectモジュールの練習
# r7のfoobarユーザのパスワードをpasswdコマンドで変えてみる
# - 事前にfoobarユーザは作ってあるものとする(useradd foobar)
# - テストが終わったらfoobarユーザは消すこと(userdel foobar)
#
# # passwd foobar
# Changing password for user foobar.
# New password:
# Retype new password:
# passwd: all authentication tokens updated successfully.
@heiwa4126
heiwa4126 / install_pexpect.yml
Created March 24, 2021 07:18
RHEL7のrootローカルにpython2用のpexpectを入れるansible。[ansible.builtin.expect](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/expect_module.html) 用。2020-03時点ではpexpect==4.8.0が入る
- name: install pexpect to root locally on RHEL7
hosts: linux
become: true
gather_facts: false
tasks:
- name: install pip2 package for python2
yum:
name: python2-pip # pip2.7 version 8.1.2
state: latest
@heiwa4126
heiwa4126 / at_1st_and_last.yml
Created March 10, 2021 02:43
最初に1回、最後に1回なにかするAnsibleのplaybook. 各ホストからXMLファイルあつめて最後に集計する、みたいなときに使う。
- name: do anything at first and at last
hosts: hosts1
become: false
gather_facts: false
tasks:
- name: at 1st
debug:
msg: "run only on {{ inventory_hostname }} at first"
changed_when: true # notifyはchangedでないと発生しないので
@heiwa4126
heiwa4126 / find_module_example1.yml
Created March 8, 2021 07:28
Ansibleのfindモジュールの例。/etc/*.confをコントロールマシンにコピーする。Jinja2のフィルタがめんどくさいがshell:つかうよりはいいんじゃないかと。
---
- name: fetch /etc/*.conf
hosts: linux
become: false
gather_facts: false
vars:
outpath: "{{ playbook_dir }}/var/etc_conf/{{ inventory_hostname }}"
tasks:
- name: get list
@heiwa4126
heiwa4126 / index.jsp
Created December 16, 2020 08:24
Tomcatの動作チェックに日付とTomcat、JDKのバージョンがでるやつがほしいと言われたので作ったやつ。
<%@
page import="java.time.*"
contentType="text/html; charset=utf8"
%><!DOCTYPE html>
<html>
<head lang="en">
<meta charset="utf-8">
</head>
<title>Hello, Tomcat</title>
</head>
@heiwa4126
heiwa4126 / r53register.sh
Created December 15, 2020 05:54
ElasticIPなしのEC2で外部IPをroute53でFQDNをふるスクリプト
#!/bin/bash
# see [Amazon Route 53: How to automatically update IP addresses without using Elastic IPs - DEV](https://dev.to/aws/amazon-route-53-how-to-automatically-update-ip-addresses-without-using-elastic-ips-h7o)
AWS=/usr/local/bin/aws
# Extract information about the Instance
INSTANCE_ID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id/)
AZ=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone/)
MY_IP=$(curl -s http://169.254.169.254/latest/meta-data/public-ipv4/)
# Extract tags associated with instance