Showing posts with label cli. Show all posts
Showing posts with label cli. Show all posts

Monday, 27 August 2018

perl cli regex

perl -pe 's/^(.+)\/([^\s]+)\-([v0-9.]+)\-*([Final|GA|M2|rc|beta|R5]*).jar$/$2\t$3\t$4/'

Wednesday, 28 May 2014

Zenoss: CLI discovery and remodel

Become zenoss user 1st

su - zenoss 

Remodel a bunch

for i in server1 server2 server3;do zenmodeler run --now -d $i;done

Discover a bunch

for i in server1 server2 server3;do zendisc run --deviceclass=/Server/Linux --device=$i;done

Friday, 6 December 2013

aws ec2 cli filter by tag name and value

  1. aws ec2 describe-instances --filter Name=tag:Name,Values=ADS-prod-ads
The horrible syntax of "and" filters:
  1.  aws ec2 describe-instances 
    1. --filter 
      1. '{"Name":"tag:backup","Values":["yes"]}' 
      2. '{"Name":"instance-state-name","Values":["running"]}' 
    2. non-breakout view below
aws ec2 describe-instances --filter '{"Name":"tag:backup","Values":["yes"]}' '{"Name":"instance-state-name","Values":["running"]}'

Friday, 8 November 2013

Openbox: monitor laptop battery via CLI and notify-send


while (true);do acpi -b | perl -n -e 's/.*?(\d+)%.*/$1/;chomp;print "$_...";if ($_ <= 15) {`notify-send batalert:$_`};';sleep 180;done

Would like a beep, but can't get one, no PC speaker on MacBook Air and mplayer buffers.

Wednesday, 6 November 2013

Change X / Openbox screen brightness on CLI

  1. sudo apt-get -y install xbacklight
  2. xbacklight +10
  3. xbacklight +10
  4. xbacklight +10
  5. xbacklight -10
  6. xbacklight -10
  7. xbacklight -10

Wednesday, 30 October 2013

Latest aws cli tools on Redhat

  1. wget https://s3.amazonaws.com/aws-cli/awscli-bundle.zip
  2. unzip awscli-bundle.zip
  3. sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
 Result is in /usr/local/bin, so set up your PATH accordingly.

Wednesday, 23 October 2013

aws cli run-instances block-device-mappings ephemeral encrypted

aws --version => aws-cli/1.1.1 Python/2.6.8 Linux/3.4.43-43.43.amzn1.x86_64
  1. aws ec2 run-instances 
    1. --image-id 
      1. ami-eeff1122 
    2. --instance-type 
      1. m2.2xlarge 
    3. --security-group-ids 
      1. sg-eeff1122
    4. --subnet-id 
      1. subnet-eeff1122
    5. --private-ip-address 
      1. 10.0.0.2
    6. --user-data 
      1. file://meta_myserver.txt 
    7. --block-device-mappings 
      1. '[{ "DeviceName":"/dev/sdb", "VirtualName":"ephemeral0" }]'
For 50G EBS attached on boot (auto-deleted on terminate unless you override), block device mapping becomes:
  1.  '[{ "DeviceName":"/dev/sdb", "VirtualName":"ephemeral0" },{"DeviceName":"/dev/sdc","Ebs":{"VolumeSize":50}}]'
WARNING: "Ebs" is very case sensitive here.

To encrypt the Ebs volume, add "Encrypted": true to the device params like so:
  1.  {"DeviceName":"/dev/sdc","Ebs":{"VolumeSize":50,"Encrypted": true}}


Tuesday, 15 October 2013

Test exim from CLI without "mail" command

If you don't have "mail" on the CLI for whatever, weird (Redhat-based) reasons, circumvent like so:
  1. /path/to/exim -v 'user@domain'
  2. type a multi-line message here ending with blank line
  3. hit ^D to end message and send
  4. you should be returned to shell
Taken: http://atmail.com/kb/2008/testing-email-with-exim/

Wednesday, 31 July 2013

DHCP on CLI for Ubuntu-like systems


  1. Add these lines to /etc/network/interfaces, or tweak existing eth0 lines
    1. auto eth0
    2. iface eth0 inet dhcp
  2. bring it up
    1. sudo ifup eth0
  3. bring it down
    1. sudo ifdown eth0
  4. add some stuff to /etc/dhcp/dhclient.conf
    1. interface "eth0" {
    2.     prepend domain-name-servers 192.168.100.10, 8.8.8.8, 8.8.4.4;
    3.     supersede domain-search "mydom.com", "mydom-vpc.internal";
    4. }
  5. flush on occasion
    1. ip addr flush eth0

Thursday, 18 July 2013

Zenoss: remodel all Linux servers at once



  1. su - zenoss
  2. zenmodeler run --path=/Server/Linux 

Monday, 15 July 2013

Selenium test on CLI in 5 minutes using Java

This took me two weeks to nail down looking at it here and there.
  1. mkdir stests
  2. cd stests
  3. wget http://selenium.googlecode.com/files/selenium-java-2.33.0.zip
  4. unzip selenium-java-2.33.0.zip
  5. mkdir jars
  6. find selenium-2.33.0 -type f -name '*jar' -exec mv -v {} jars \;
  7. rm -rfv selenium-*
  8. mkdir src
  9. vi src/Test.java
    1. use below code
  10. mkdir out
  11. javac -d out -cp 'jars/*' src/MyTest.java
    1. ignore "Notes" output
  12. cd out
  13. rm -rfv org
  14. java -cp '../jars/*:.' MyTest

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;

public class MyTest  {
    public static void main(String[] args) {
        WebDriver driver = new FirefoxDriver();
        driver.get("http://www.google.com");
        WebElement element = driver.findElement(By.name("q"));
        element.sendKeys("Cheese!");
        element.submit();
        System.out.println("Page title is: " + driver.getTitle());
        (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
            public Boolean apply(WebDriver d) {
                return d.getTitle().toLowerCase().startsWith("cheese!");
            }
        });
        System.out.println("Page title is: " + driver.getTitle());
        driver.quit();
    }
}

Friday, 3 May 2013

mysqldump between two servers over ssh


  1. set up ssh keys so server1 user can ssh to a server2
  2. set $HOME/.my.cnf so both users can get into respective mysql cli without passwords
    1. see below for sample file
  3. create the new, empty database on server2, receiving server
  4. from server1
    1. mysqldump mydatabase | ssh server2 mysql mydatabase

# $HOME/.my.cnf
[client]
password=myusersmysqlpassword

Thursday, 25 April 2013

tcpdump HTTP headers


  1. tcpdump -vvvs 1024 -l -A port 80 | egrep '^[A-Z][a-zA-Z\-]+:|GET|POST'
    1. Match your port, here it is 80, could be 8080 or 443, e.g.

Quick CLI screenshots on Linux or Openbox / Fluxbox


  1. sudo apt-get -y install imagemagick eog
  2. import myscreenshot.jpg
    1. select portion of screen with the crosshairs
  3. eog myscreenshot.jpg

Wednesday, 24 April 2013

Thursday, 28 March 2013

Run one command on many Linux servers, install pssh, works on Mac


  1. sudo easy_install pip
  2. sudo pip install pssh
  3. Create a file with the list of servers you want to control, call it servers or something similar
  4. pssh -h servers "date"
  5. Put your ssh pub key up to all of them
    1. pssh -h servers -i "echo 'ssh-rsa AA...wh me@myfqdn' >> /home/user/.ssh/authorized_keys"
Taken: http://kaspergrubbe.dk/2012/using-pssh-for-executing-parallel-ssh-commands/

Note: csshX is very nice if you want to see all terminals at once as you type, more later

Monday, 25 March 2013

Generate gpg keys, upload to server, pull from server, from CLI


  1. gpg --gen-key
  2. gpg --list-keys
  3. gpg --keyserver pgp.mit.edu --send-keys '62E49F5A'
    1. that funky number is listed in the output of "list-keys", just look carefully
      1. your funky number will be unique
      2. should be 8 digits long and hex
  4. gpg --keyserver pgp.mit.edu --search-keys 'youremail@yahoo.com'
  5. gpg --keyserver pgp.mit.edu --search-keys 'yourgirl@yahoo.com'
  6. gpg --keyserver pgp.mit.edu --recv-keys 1F3B6ACA
    1. Get her key with the ID you saw in previous step
  7. Use keys to encrypt content
    1. Can be encrypted for multiple people in one go, and only those listed can open the result

Friday, 15 March 2013

Redirect all command output, stdin/stderr, to a file on Linux

puppet agent --test --noop >/var/tmp/puppet_noop_20130315 2>&1

Notes:
  1. The 2>&1 redirects stderr to where stdin points
    1. stdin points to the console by default unless you change that
    2. here stdin is redirected to a file under /var/tmp


Wednesday, 6 February 2013

Monday, 8 October 2012

sed with the capital E option on the Linux CLI

No, you are not crazy, sed on Linux has a secret, BSD compatible option, -E that is equivalent to -r.

Interview questions: 2020-12

Terraform provider vs provisioner Load balancing Network Load Balancer vs Application Load Balancer  Networking Layer 1 vs Layer 4 haproxy u...