Posts Tagged ‘bash’

Git jira hook

This is a git hook to update JIRA server with commit info. This is a simple set of bash scripts which can be used to update a jira server with git commit information.

This work as following:

  • When a user writes a commit message in git it used the name of a JIRA issue in the format CODE-XXXX (ie. JVIN-7893). Multiple issues separated by comma are supported. Each will be updated.
  • On push the server post-receive hook updates the corresponding JIRA issue via REST API.
  • The issue custom field will be updated to contain (note that this is JIRA wiki code)

See more on gitHub

Router reboot wrapper script

This is a memory sink article. I found this nice python script which reboots a B525 router and wanted to write a wrapper script around it.

#!/bin/bash

# refs: https://github.com/jinxo13/HuaweiB525Router, https://github.com/mkorz/b618reboot

RUNDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

MAX_ATTEMPTS=10
ATTEMPT=0
TIMEOUT=60
LOCK_FILE=$RUNDIR/lock
REMOTE=google.com
LOCAL=192.168.7.1

if [ -f $LOCK_FILE ]; then
    echo "Already running, exiting"
    exit -1
fi

function finish {
  rm $RUNDIR/lock
}
trap finish EXIT

touch $RUNDIR/lock

while (( $ATTEMPT < $MAX_ATTEMPTS ))
do
    DATE=$(date +%Y%d%m-%H%M%S)
    echo -e "GET http://$REMOTE HTTP/1.0\n\n" | nc $REMOTE 80 > /dev/null 2>&1

    if [ $? -eq 0 ]; then
        echo "$DATE: Online"
        break
    else
        ping -c1 -w1 LOCAL > /dev/null 2>&1

        if [ $? -eq 0 ]; then
            echo "$DATE: Internet offline, router online, trying to reboot router, waiting $TIMEOUT"
            $RUNDIR/b618reboot/reboot_router.py
        else
            echo "$DATE: Internet offline, router offline, waiting $TIMEOUT"
        fi

        sleep $TIMEOUT
        ATTEMPT=$(( ATTEMPT + 1 ))
        TIMEOUT=$(( TIMEOUT * 2 ))
    fi
done

Simple pomodoro script

This is a very basic pomodoro script I am using to avoid getting in a fixed position for hours at a time:

#!/bin/bash
 
UNIT=5
UNIT_CNT=5
PAUSE=6
 
notify-send -i clock "Starting interval..."
 
for i in $(seq $UNIT_CNT); do
    sleep ${UNIT}m
    let c=$i*$UNIT
    notify-send -i clock "$c minutes"
done
 
(for i in $(seq $PAUSE); do let c=$PAUSE-$i+1; echo -n "Pause ${c}m"; echo -e '\f'; sleep 1m; done; echo -e '\f'; echo "Work";) | sm -

(X)Ubuntu microphone mute/unmute script

The goal of this script was to have a simple script, binded with a shortcut which allows to mute/unmute all the microphones and to display a nice notification in the process. This is the simplest version working on xubuntu 14.04 with pulseaudio.

mute.sh

#!/bin/bash
 
ACTION=1 #1 mute, 0 unmute
SCNT=$(pacmd list-sources | grep muted | wc -l)
 
MUTED=$(pacmd list-sources | grep muted | grep yes)
if [ $? == 0 ]; then
    ACTION=0
    notify-send -i microphone-sensitivity-medium "Microphone" "Unmutting $SCNT sources..."
else
    notify-send -i microphone-sensitivity-muted "Microphone" "Mutting $SCNT sources..."
fi
 
#SRC=$(seq $SCNT)
SRC=$(pacmd list-sources | grep index | cut -d':' -f2 | tr -d ' ')
 
for i in $SRC; do
    #let s=$i-1
    pacmd set-source-mute $i $ACTION
done