Skip to content

Instantly share code, notes, and snippets.

@dhval
Last active September 15, 2021 18:25
Show Gist options
  • Save dhval/0673f190e4cbb505881987c5b69ec1c6 to your computer and use it in GitHub Desktop.
Save dhval/0673f190e4cbb505881987c5b69ec1c6 to your computer and use it in GitHub Desktop.
Shell Scripts Snippets
  • She bang line, location of shell which bash
  • Store arguments from bash in array args=("$@")
  • Number of arguments count=("$#")
  • Date NOW=$(date +"%m-%d-%Y")
  • Print a random file files=(./*); printf "%s\n" "${files[RANDOM % ${#files[@]}]}"
  • Create empty dir [ -d "./data" ] && mkdir data || rm -rf ./data/*

Iteration

Moves selected files

find $PWD -type f -not -name "*mp4" -not -name "*png" | xargs -I '{}' mv '{}' ~/Downloads/

Renaming files -n {Dry-run}

rename -n "s/[\W]+/./g" my_File

ls | while read -r FILE
do
   mv "$FILE" `echo $FILE | tr ' ' '_' | tr -d '[{}(),\!]' \
      | tr -d "\'" | tr '[A-Z]' '[a-z]' | sed 's/_-_/_/g'`
done

Pad digits for string comparison, e.g. Chapter1.mp3 to Chapter01.mp3 rename -ne 's/\d+/sprintf("%02d",$&)/e' -- *.mp3

Strip simple xml file into element, value pairs.

cat warrant.xml | grep -o "<[[:alpha:]]*>" \
 | sed "s/<//" | sed "s/>//" \
 | awk '{print "String "$1" = \""$1"\";"}'

Permissions

sudo chmod 755 /usr/local/lib
sudo chown -R $USER:admin /usr/local

SSH

** Find $PATH on remote host **

ssh rhost "echo \$PATH"

** Add ssh keys to remote host. **

cat ~/.ssh/id.pub | ssh rhost "cat >> ~/.ssh/authorized_keys"

diff & fdupes

** fdupes finding duplicate files, recursively. **

diff - b=ignore_space_change | r=recursive | q=quiet, only file name

fdupes -S -r /path/to/folder
fdupes -rdN dir/
diff -brq sr1 src2              

Bracket expansion

echo file{1..4}.txt

Restarting a program in windows, if not already running.

tasklist /FI "IMAGENAME eq Tunnelier.exe" 2>NUL | find /I /N "Tunnelier.exe">NUL
if "%ERRORLEVEL%"=="0" (
  echo Programm is running
) else (
	start "D" "C:\Program Files\Bitvise Tunnelier\Tunnelier.exe" -loginOnStartup
)	

Ubuntu house keeping

  • Set java version sudo update-alternatives --config java
  • Search for packages apt search openjdk-11-jdk
alias fix-files="rename 's/[\W]+/./g'"
alias cgwsync="rsync -avurz /cygdrive/m/ nexus:/media/dhval/"
alias tun1="autossh -M 20092 -f -N -R 9922:localhost:22 dhval"
alias tun2="autossh -M 23092 -f -N -L 22:localhost:22 nexus"
#!/bin/bash
generate-thumbnails() {
for filename in *.mp4; do
echo $filename
ffmpeg -i "$filename" -r 1/15 -vf scale=-1:120 -vcodec png capture-%002d.png
sleep 1
echo $filename
montage -title "Movie Name\nSubtitle" -geometry +4+4 capture-*.png "$filename".png
sleep 1
rm capture-*.png
done
}
maven-deploy() {
mvn deploy:deploy-file \
-Durl=http://oa5tppjnet200.pa.lcl:8081/artifactory/simple/libs-release-local/ \
-Dfile=target/base-js-0-SNAPSHOT.jar \
-Dpackaging=jar \
-DgroupId=jnet.web.common.js \
-DartifactId=base-js \
-Dversion=1.0.9 \
-DrepositoryId=central
}
list_files() {
files=(~/Movies/Hi_Movies/*)
COUNT=${#files[@]}
for ((i=0; i<=$COUNT; i++));
do
echo "${files[$i]}"
done
}
### Queries pogplug over https page and spit out results ###
### Since we get result back in case of failures only, we have to to write cmd to file & execute it.
function exec_hbplug
{
PORT=$1
shift
CMD="echo \"$*\" > run.sh;chmod +x run.sh;sh run.sh > out 2>&1;cat out"
# CMD="echo \"$*\" > run.sh%3Bchmod %2Bx run.sh%3Bsh run.sh > out 2>%261%3Bcat out"
ARG=$(echo $CMD | sed 's/+/%2B/g;s/ /+/g;s/;/%3B/g;s/&/%26/g')
echo $ARG
curl -k -q "https://root:ceadmin@localhost:"$PORT"/sqdiag/HBPlug?action=command&command=""$ARG" 2>/dev/null | sed '/^$/d;1,2d;$d'
# while read r;do echo $r;done < /tmp/plug
}
# Remove unwanted characters.
function fname {
echo $(basename "$1" | tr -d ")(][" | sed -e 's/ /\./g;s/(/\\\(/g;s/)/\\\)/g')
}
function handbrake {
# List all media files size > 100M. Escape space and bracket character
find /media/torrent -size +100M -type f -not -name "*.mp4" -not -name "*.part" | while read -r FILE
do
filename=$(basename "$FILE")
extension=${filename##*.}
filename=${filename%.*}
OUT="/media/transmission/"$(fname $filename)".mp4"
[ ! -e "$OUT" ] && HandBrakeCLI -i "$FILE" -o "$OUT" -e x264 -q 22 -r 12 -B 64 -X 480 -O
done
}
alias swats="exec_hbplug $* 8443"
alias ipod="exec_hbplug $* 9443"
# *** Update this $AB__URL with your BROADCAST key e.g. rtmp://live.justin.tv/app/live_XXXXXXXX
source ~/conf/vars.sh
# -vcodec copy -acodec copy, use this if you run into codec issues.
OPT="-r 20 -s 640x360 -qscale:v 5 -vcodec copy -acodec libmp3lame -ar 44100 -b:a 64k -f flv"
# Some Meta information about your video
META="-metadata title=$file"
# -re (input) Read input at native frame rate, by default ffmpeg attempts to read the input(s) as fast as possible.
ffmpeg -re -f concat -i ~/tmp/list.txt $OPT -metadata title="$file" $AB_URL
#!/bin/bash
OUT="/home/logs/hi.txt"
function is_offline {
wget -q --tries=2 --timeout=3 http://google.com >/dev/null 2>&1 && return 1 || return 0
}
function wlan_stat {
active=`ethtool wlan0 2> /dev/null | grep "Link detected: no" | grep -o no`
if [ ! -z $active ] && [ $active == "no" ]; then
return 1
fi
return 0
}
function reload {
is_offline && shutdown -r now
}
function wifi {
wlan_stat=`ip link show wlan0 2> /dev/null | grep -o "state UP" | grep -o UP`
is_offline
if [ "$?" == 0 ]; then
# ip link set wlan0 up && wpa_supplicant -iwlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf & dhcpcd wlan0
echo "Attempt to restart wireless" >> $OUT
systemctl restart wireless.service
return 0
fi
return 1
}
function autosh {
ip_info=`curl ipinfo.io/ip --connect-timeout 5 2> /dev/null`
proxy_down=`ssh nexus "nc -vz localhost 9443" 2>&1 | grep -o "succeeded"`
if [ ! -z $ip_info ] && [ -z $proxy_down ]; then
echo "Attempt to restart autossh" >> $OUT
systemctl restart autossh.service
else
echo "Active autossh !" >> $OUT
fi
}
alias proxy="export http_proxy=http://localhost:11050/"
tx30 () {
ifconfig wlan2 down
iw reg set BO
iwconfig wlan2 txpower 30
ifconfig wlan2 up
}
ipfwd () {
iptables -t nat -F
iptables -F
iptables -t nat -A POSTROUTING -o wlan2 -j MASQUERADE
iptables -A FORWARD -i wlan0 -o wlan2 -j ACCEPT
echo '1' > /proc/sys/net/ipv4/ip_forward
service hostapd restart
service dnsmasq restart
}
alias wi_check="airmon-ng check"
wi() {
wi_check
}
wi2 () {
airmon-ng check wlan2 kill
wpa_supplicant -iwlan2 -c /etc/wpa_supplicant/wpa_supplicant.conf & dhcpcd wlan2
service hostapd restart
service dnsmasq restart
route add default gw 192.168.1.1
}
alias reload="source alias.sh"
alias wi_scan="iwlist wlan2 scan"
alias mon="airodump-ng mon0"
alias wi_start="airmon-ng start wlan2"
alias wi_stop="airmon-ng stop wlan2"
alias wi_kill="airmon-ng check kill"
alias wpa="wpa_supplicant -iwlan2 -c /etc/wpa_supplicant/wpa_supplicant.conf & dhcpcd wlan2"
alias addgw="route add default gw 192.168.1.1"
alias dnsmasq="service dnsmasq start"
alias traffic="iftop -f 'not ip dst net 192.168.1.0/24'"

Cloning a partition

dd if=/dev/sda1 of=/dev/sdb1 bs=4096 conv=notrunc,noerror,sync

[Mount in](http://www.razva.ro/install-arch-linux-pogoplug-samba-pogoplug-4/) /etc/fstab
/dev/sdb1 /mnt/usbdrive ext4 defaults 0 0
Mount your usb drives, /dev/disk/by-path or /proc/partitions
mount -t vfat /dev/sda1 /mnt/usb
Mount as RW
mount -o rw,remount /
Mount as RO
mount -o ro,remount /
Format & FSCHK
fdisk -c=dos /dev/sda1
e2fsck –f /dev/sda1
Use c option to allow block to start from 63
Setup time, host name & change passwd.
timedatectl set-timezone America/New_York
timedatectl set-time "2014-08-11 15:45:54"
hostnamectl set-hostname alarm
pacman -Syu --ignore filesystem --ignore ca-certificates
pacman -S git dialog wireless_tools vim traceroute wpa_supplicant ddclient screen autossh rsync
See connected usb devices
lsusb
List devices
lsblk -f
Join wifi n/w through gui
wifi-menu
Join using netctl
/etc/netctl# install -m640 examples/wireless-wpa wireless vim /etc/netctl/wireless, set ssid & pwd, TimeoutUP=500, TimeoutCarrier=500
Manually connect to wifi.
iwconfig
ip link set wlan0 up
iwlist wlan0 scan
wpa_passphrase wifi_ssid "wifi_password" > /etc/wpa_supplicant.conf
wpa_supplicant -iwlan0 -c /etc/wpa_supplicant.conf & dhcpcd wlan0
Find pogoplug on network
for((i=10;i<255;i++)); do nc -vz -w 2 172.19.10.$i 22 2>&1 | grep open; done
crontab - [e|l]

Config location:

cat /etc/iptables/iptables.rules

Make rules persistent.

iptables-save

Log any outgoing going traffic towards internet.

iptables -A OUTPUT -p tcp -o eth0 ! -d 172.19.10.0/24 -j LOG --log-prefix='[netfilter]'

Disable port 443 accept from your host, to prevent Curl root access

iptables -A INPUT -p tcp --dport 443 ! -s 172.19.10.172 -j DROP

See all enabled services

systemctl list-unit-files | grep enabled

Disable logging, comment “#” out line in /etc/syslog-ng/syslog-ng.conf

systemctl < status | is-enabled | start | stop | enable> ddclient

journalctl -xn

/usr/lib/systemd/system/pogoplug.service
/usr/local/cloudengines/pogoplug.sh
/etc/pogoplug.conf
/usr/local/cloudengines/hbplug.conf

curl -k "https://root:ceadmin@192.168.1.129/sqdiag/HBPlug?action=command&command=ls";

Rasberry pi links

http://raspberrypi.stackexchange.com/questions/7987/wifi-configuration-on-arch-linux-arm http://gleenders.blogspot.com/2014/03/raspberry-pi-resizing-sd-card-root.html http://raspberrypi.stackexchange.com/questions/499/how-can-i-resize-my-root-partition http://qdosmsq.dunbar-it.co.uk/blog/2013/06/beginners-guide-to-arch-linux-on-the-raspberry-pi-part-2/comment-page-1/ http://archpi.dabase.com/ # general install guide

References :-

Qui's UBOOT Stuff

Qui's Interesting ARM stuff

ARM install instruction

arch-linux-pogoplug uBoot Flashing Utilities

Perfomance tunning

export AUTOSSH_PIDFILE=~/autossh.pid
export AUTOSSH_LOGFILE=~/autossh.log
export AUTOSSH_POLL=60
export AUTOSSH_FIRST_POLL=30
export AUTOSSH_GATETIME=0
export AUTOSSH_DEBUG=1
#autossh -M 0 -4 -N dhval -R 9922:localhost:22 -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -o BatchMode=yes -o StrictHostKeyChecking=no
#autossh -M 0 -4 -N nexus -L 22:localhost:22 -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -o BatchMode=yes -o StrictHostKeyChecking=no
autossh -M 20092 -f -N -R 9922:localhost:22 dhval
autossh -M 23092 -f -N -L 22:localhost:22 nexus
# https://wiki.archlinux.org/index.php/Secure_Shell#Autossh_-_automatically_restarts_SSH_sessions_and_tunnels
# Location, /etc/systemd/system/autossh.service
[Unit]
Description=AutoSSH service
After=network.target
[Service]
Environment="AUTOSSH_GATETIME=0"
ExecStart=/usr/bin/autossh -M 0 -NR 9443:0.0.0.0:443 nexus -o ServerAliveInterval=600 -o ServerAliveCountMax=30 -o TCPKeepAlive=yes nexus
[Install]
WantedBy=multi-user.target
Alias=autossh.service
REM This file generate stubs for the provided WSDL
REM Look available options http://axis.apache.org/axis2/java/core/docs/reference.html
:: -d Valid databinding(s) are adb, xmlbeans, jibx and jaxbri (Default: adb).
:: -t Generate Test Cases
:: --ns2p http://sample.org/schema/../foo/bar=foo.bar
:: -pn Specify port in multiple port service
:: -o output folder
set JAVA_HOME=C:\tools\jdk1.7.0_09
set PATH=C:\tools\jdk1.7.0_09\bin;%PATH%
set ANT_HOME=c:\tools\ant-1.8.4
set PATH=%PATH%;%ANT_HOME%\bin
set AXIS2_HOME=C:\tools\axis2-1.6.2\
set PATH=%PATH%;%AXIS2_HOME%\bin
set M2_HOME=C:\tools\maven-3.0.4
set M2=%M2_HOME%\bin
set PATH=%PATH%;%M2%
set PATH=%PATH%;C:\tools\
wsdl2java.bat -t -d xmlbeans -Ejavaversion 1.5 -uri wsdlfile.wsdl^
-pn VehicleQuerySOAPPort --ns2p http://www.company.com/service/package/BackgroundCheck/1=package.webservice,^
http://www.company.com/niem/package/metadata/1=package.webservice.niem
REM invoke a batch command similar to shell function.
set "rsync=java -cp c:\tools\rsync4j\* com.github.fracpete.rsync4j.RSync -vur --progress"
%rsync%
OPT="-qscale:v 9 -vcodec copy -acodec copy -ar 44100 -b:a 16k -f flv"
META="-metadata title=$file"
source ~/conf/vars.sh
while (true); do
files=(~/btsync/fear-files/*)
file="${files[RANDOM % ${#files[@]}]}"
echo -e "*****\n Current file" $file "\n*****"
ffmpeg -re -i "$file" $OPT -metadata title="$file" $ZTV_URL
done
I discovered some of my media won't play in plex even when encoded by handbrake. This script tries to look up video information using "mplayer" tool, any video that has fps as "nan" is the culprit. Probably it was encoded without --optimize or --fast-start flags.
# http://askubuntu.com/questions/249828/command-to-see-media-file-info-in-terminal
# http://askubuntu.com/questions/303454/get-information-about-a-video-from-command-line-tool
# http://forums.macrumors.com/showthread.php?t=1496052
find . -name "*.mp4" -print -exec \
mplayer -vo null -ao null -identify -frames 0 {} 2>/dev/null \; \
| grep -B 15 "nan fps" 2>/dev/null \
| grep Playing \
| cut -d " " -f 2
apply plugin: 'java'
version = '1.0'
sourceCompatibility = 1.8
targetCompatibility = 1.8
//create a single (fat) Jar with all dependencies
task fatJar(type: Jar) {
manifest {
attributes 'Implementation-Title': 'Gradle Jar File Example',
'Implementation-Version': version
}
baseName = project.name + '-Fat'
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
}
//create a jar file with libs
jar {
baseName = project.name + '-Small'
into('lib') {
from 'lib'
}
manifest {
attributes(
'Manifest-Version': '1.0',
'Class-Path': 'lib/NAMCommon.jar lib/nidp.jar lib/nxpe.jar'
)
}
}
dependencies {
compile files('lib/NAMCommon.jar', 'lib/nidp.jar', 'lib/nxpe.jar')
}
#!/bin/bash
# You need to change SRC -- Sourse folder and DEST -- Destination folder
# The mp4 format is 480x270
SRC=/media/fat/media/encode/
TOR=/media/torrent/
DEST=/media/fat/media/out/
DEST_EXT=mp4
HANDBRAKE_CLI=HandBrakeCLI
# Move all torrented mp4 files to destination directory.
find $TOR -mindepth 2 -type f -size +50M -not -name "*.part" -exec mv {} $DEST \;
# Normalize files names, handbrakes chokes on bad file name.
python ~/scripts/normalize.py
# List all media files size > 100M. Escape space and bracket character
find $SRC -size +100M -type f -not -name "*.mp400000000" -not -name "*.part" | while read -r FILE
do
filename=$(basename "$FILE")
extension=${filename##*.}
filename=${filename%.*}
echo "***************************** \n" $FILE "********************\n"
OUT="$DEST"$(echo $filename | tr -d '[)(]-' )".$DEST_EXT"
[ ! -e "$OUT" ] && echo "\n***\n --- $FILE --- \n***\n" "-->" "$OUT --- \n\n" && echo "" | $HANDBRAKE_CLI -i "$FILE" -o "$OUT" -e x264 -q 22 -r 12 -B 64 -X 480 -O
done
#!/bin/bash
SRC="/Users/dhval/Downloads/"
DEST="/Users/dhval/Movies/"
DEST_EXT=mp4
HANDBRAKE_CLI=HandBrakeCLI
# List all media files size > 100M. Escape space and bracket character
find $SRC -size +100M -type f -name "*.mp4" -o -name "*.mkv" -o -name "*.avi" -o -name "*.wmv" | while read -r FILE
do
filename=$(basename "$FILE")
extension=${filename##*.}
filename=${filename%.*}
OUT="$DEST"$(echo $filename | sed -e 's/-/./g' | tr -d '[)(]-' )".$DEST_EXT"
[ ! -e "$OUT" ] && echo "\n\n --- $FILE" "-->" "$OUT --- \n\n" && echo "" | \
$HANDBRAKE_CLI -i "$FILE" -o "$OUT" -O --preset="iPad"
done
OPT="-qscale:v 9 -cpuflags armv5te -vcodec copy -acodec copy -ar 44100 -b:a 16k -f flv"
META="-metadata title=$file"
source ~/conf/vars.sh
while (true); do
files=(~/btsync/hindi/*)
file="${files[RANDOM % ${#files[@]}]}"
echo -e "*****\n Current file" $file "\n*****"
ffmpeg -i "$file" $OPT -metadata title="$file" $AB_URL
done
#!/bin/bash
route del default gw 192.168.1.10
route add default gw 192.168.1.1
# Set Trace
set -x
### iptables for kali router ###
# Flush and create chains.
iptables -t mangle -F
iptables -t mangle -X LOGGING
iptables -t mangle -X IPHONE
iptables -t mangle -X IPAD
iptables -t mangle -X MAC
iptables -t mangle -N TRAFFIC
iptables -t mangle -N IPHONE
iptables -t mangle -N IPAD
iptables -t mangle -N MAC
# Filter table
iptables -F
iptables -X SNITCH
iptables -N SNITCH
iptables -X EVIL
iptables -N EVIL
# Halt on error
set -e
# Always pass traffic to local subnet,google,apple,idea cellular
iptables -t mangle -A PREROUTING -d 192.168.1.1/24 -j RETURN
iptables -t mangle -A PREROUTING -s 71.57.239.190 -j RETURN
iptables -t mangle -A PREROUTING -d 71.57.239.190 -j RETURN
iptables -t mangle -A PREROUTING -p tcp ! --dport 32400 -m mac --mac-source fc:f8:ae:7e:eb:e0 -j DROP
iptables -t mangle -A PREROUTING -p tcp ! --dport 32400 -s 192.168.1.17 -j DROP
iptables -t mangle -A PREROUTING -p tcp --match multiport --dports 80,443 -d 74.125.0.0/16 -j RETURN
iptables -t mangle -A PREROUTING -p tcp --match multiport --dports 80,443 -d 17.178.0.0/16 -j RETURN
iptables -t mangle -A PREROUTING -p tcp --match multiport --dports 80,443 -d 223.196.0.0/16 -j RETURN
# Devices specific traffics redirected to devices chains
iptables -t mangle -A PREROUTING -p tcp -m mac --mac-source 80:e6:50:82:e1:08 -j IPAD
iptables -t mangle -A PREROUTING -p tcp -m mac --mac-source 4c:8d:79:d7:49:a0 -j MAC
iptables -t mangle -A PREROUTING -p tcp -m mac --mac-source 4c:8d:79:5a:22:62 -j IPHONE
# Shape traffic (using traffic control)
iptables -t mangle -A PREROUTING -p tcp --match multiport --sports 80,443 -s 74.125.0.0/16 -j RETURN
iptables -t mangle -A PREROUTING -p tcp --match multiport --dports 80,443 -j TRAFFIC
iptables -t mangle -A PREROUTING -p tcp --match multiport --sports 80,443 -j TRAFFIC
# Chain for traffic control
iptables -t mangle -A TRAFFIC -j MARK --set-mark 6
# Chain for iphone
iptables -t mangle -A IPHONE -m limit --limit 3/min -j LOG --log-prefix " :::: iphone denied :::: "
iptables -t mangle -A IPHONE -j DROP
# Chain for ipad
iptables -t mangle -A IPAD -m limit --limit 3/min -j LOG --log-prefix " :::: ipad denied :::: "
iptables -t mangle -A IPAD -j DROP
# Chain for mac
iptables -t mangle -A MAC -m limit --limit 3/min -j LOG --log-prefix " :::: MAC denied :::: "
iptables -t mangle -A MAC -j DROP
# Chain for evil (lil snitch) net
iptables -A EVIL -m limit --limit 5/min -j LOG --log-prefix " :::: EVIL !! :::: "
iptables -A EVIL -j DROP
# Chain for forwarded traffic
iptables -A SNITCH -p icmp -j RETURN
iptables -A SNITCH -m mac --mac-source 00:24:d6:50:d3:ee -j DROP
iptables -A SNITCH -s 192.168.1.17 -j DROP
iptables -A SNITCH -p tcp --match multiport --dports 80,443,11050 -j RETURN
iptables -A SNITCH -m limit --limit 3/min -j LOG --log-prefix " :::: SNitCH :::: "
iptables -A SNITCH -j DROP
iptables -A FORWARD -d 46.4.223.213 -j EVIL
iptables -A FORWARD ! -d 192.168.1.1/24 -j SNITCH
set +x
set +e
# Select a random file to stream to justin tv
files=(./video-files-dir/*)
file="${files[RANDOM % ${#files[@]}]}"
echo -e "*****\n Current file" $file "\n*****"
# Use fmpeg concat option instead
for file in *.mp4; do echo "file '$(pwd)/$file'"; done > "concatlist.txt"
# *** Update this URL with your BROADCAST key e.g. rtmp://live.justin.tv/app/live_XXXXXXXX
URL="rtmp://live.justin.tv/app/live_58491283_y1twPWju7YvVVbCeM4tK18lRp8mLuinvalid"
# -vcodec copy -acodec copy, use this if you run into codec issues.
OPT="-r 20 -s 640x360 -qscale:v 5 -vcodec libx264 -acodec libmp3lame -ar 44100 -b:a 64k -f flv"
# Some Meta information about your video
META="-metadata title=$file"
# If you haven't install ffmpeg to broadcast to justin.tv using "rtmp://" protocol. Do brew install ffmpeg
# -re (input) Read input at native frame rate, by default ffmpeg attempts to read the input(s) as fast as possible.
ffmpeg -re -f concat -i "concatlist.txt" $OPT -metadata title="$file" $URL
#!/bin/bash
source ~/conf/vars.sh
echo "To stop me :"
echo "kill -stop $0"
PID_FILE=$(basename $0)".pid"
ABORT=0
COM=$1
PIPE=$2
STREAM=$3
URL=$4
FF_OPT="-r 20 -s 640x360 -qscale:v 5 -vcodec copy -acodec libmp3lame -ar 44100 -b:a 64k -f flv"
source ~/conf/vars.sh
echo "$PID_FILE : $$"
echo "$$" "\t" "$(date)" "\t" "$@" >> $PID_FILE
trap stop stop
stop() {
echo "int stop";
$ABORT=1
exit 0
}
while (( $ABORT != 1 )); do
case "$1" in
-rt)
echo "rtmp -y " $STREAM "-o" $PIPE
rtmpdump -r "rtmp://65.51.67.40:1935/rtplive" -a "rtplive" -f "LNX 11,2,202,335" \
-W "http://www.reliableiptv.com/usa/player_s4_0.swf" -p "http://www.reliableiptv.com" \
-y "$STREAM" -o $PIPE
;;
-ff)
echo "ffmpeg -re -i" $PIPE $FF_OPT $URL
ffmpeg -re -i $PIPE $ARM_OPT $URL
;;
*)
echo "Invalid Option, Usage :"
echo "-ff | -rt /tmp/stream reliable.stream justin.url"
;;
esac
echo "TRY AGAIN !"
sleep 20
done
#!/usr/bin/python
import os,re
from os.path import isfile, join
path = "/media/fat/media/encode/"
for file in [ f for f in os.listdir(path) if isfile(join(path, f)) and re.search("[^\w._-]", f) ]:
f = re.sub("[^\w._-]", "-", file)
newfile = join(path,f)
oldfile = join(path,file)
print oldfile + " --->>> " + newfile
os.rename(oldfile, newfile)
[Route](https://developer.apple.com/library/mac/documentation/Darwin/Reference/Manpages/man8/route.8.html)
When on Linux, I know the command by head:
'''
sudo route add -net 10.1.0.0/16 gw 192.168.120.254
'''
On the Mac the route command is similar, but a bit different :
'''
sudo route -n add -net 10.1.0.0/16 172.19.10.1
'''
JAVA_HOME is expanded to /System/Library/Frameworks/JavaVM.framework/Versions/1.5/Home.)
'''
export JAVA_HOME=$(/usr/libexec/java_home)
'''
(Mount the share: ~/Library/Preferences/nsmb.conf)[https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man8/mount_smbfs.8.html]
'''
mount_smbfs //username:password@server.name/share_name share_name/
mount_smbfs -d 755 -f 755 //weblogic/e$/Oracle/TEMP Temp/
umount shr_name
'''
The hosts file
'''
sudo nano /private/etc/hosts
dscacheutil -flushcache
'''
[Resize disk image](http://apple.stackexchange.com/questions/60613/change-dmg-capacity)
'''
hdiutil resize -size 25G /PATH/TO/DISK/IMAGE.dmg
'''
#
on run {targetBuddyPhone, targetMessage}
tell application "Messages"
set targetService to 1st service whose service type = iMessage
set targetBuddy to buddy targetBuddyPhone of targetService
send targetMessage to targetBuddy
end tell
end run
#!/bin/bash
# A for-in loop, if-fi
count=0;
for line in `cat $1`; do
myHost=`echo $line | cut -d, -f 1 | tr -d "\'"`
count=$(ping -4 -n $COUNT $myHost | grep -i "received" | awk -F',' '{ print $2 }' | awk -F'=' '{ print $2 }')
if [ ! $count -eq 0 ]; then
# 100% failed
echo "$line, '$(date +"%m-%d-%Y")'"
fi
done
tr -d '\15' < $line.bak > $line
findp()
{
local ipAdress=$(echo "dhvalm.dyndns.org" | xargs nslookup | grep -Eo '([[:xdigit:]]{1,3}\.){3}[[:xdigit:]]{1,3}' | xargs | awk '{print$3}')
echo "dhvalm.dyndns.org >> " $ipAdress;
}
findp "dhvalm.dyndns.org"
TE=2kbps
CEIL=5kbps
case "$1" in
hi)
RATE=20kbps
CEIL=35kbps
;;
mi)
RATE=10kbps
CEIL=15kbps
;;
lo)
RATE=1kbps
CEIL=2kbps
;;
st)
tc -s qdisc ls dev eth0
exit 0
;;
rm)
tc qdisc del dev eth0 root
echo "tc filter removed"
exit 0
;;
**)
RATE=2kbps
CEIL=5kbps
;;
esac
echo $RATE
echo $CEIL
tc qdisc del dev eth0 root
tc qdisc add dev eth0 root handle 1:0 htb default 10
tc class add dev eth0 parent 1:0 classid 1:10 htb rate $RATE ceil $CEIL prio 0
tc filter add dev eth0 parent 1:0 prio 0 protocol ip handle 6 fw flowid 1:10
#!/bin/bash
### http://stackoverflow.com/questions/11203201/how-to-stop-infinite-loop-in-bash-script-gracefully ###
echo "To stop me :"
echo "kill -stop $0"
PID_FILE=$(basename $0)".pid"
ABORT=0
echo "$PID_FILE : $$"
echo "$$" > $PID_FILE
trap stop stop
stop() {
echo "int stop";
$ABORT=1
exit 0
}
# Use (( since its numerical comparison
while (( $ABORT != 1 )); do
echo "d"
sleep 2
done
# https://wiki.archlinux.org/index.php/Wireless_network_configuration#Manual_wireless_connection_at_boot_using_systemd_and_dhcpcd
# Location, /etc/systemd/system/wireless.service
# e.g systemctl enable wireless.service
[Unit]
Description=Wireless network connectivity (wlan0)
Wants=network.target
Before=network.target
BindsTo=sys-subsystem-net-devices-wlan0.device
After=sys-subsystem-net-devices-wlan0.device
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/ip link set dev wlan0 up
ExecStart=/usr/bin/wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
ExecStart=/usr/bin/dhcpcd wlan0
ExecStart=route add -net 71.57.239.0/24 gw 192.168.1.1
ExecStop=/usr/bin/ip link set dev wlan0 down
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment