Skip to content

Instantly share code, notes, and snippets.

View benwei's full-sized avatar

ben6 benwei

View GitHub Profile
@benwei
benwei / dict.sh
Created October 26, 2015 04:38
simple dictionary using curl with dict protocol
#!/bin/sh
## refernce http://www.dict.org/rfc2229.txt
word="$1"
if [ -z "$word" ]; then
echo "syntax: ./dict <word>"
exit 1
fi
curl "dict://dict.org/d:$word"
@benwei
benwei / date_convert_osx_example.sh
Created January 28, 2016 04:16
MacOS convert timestamp by date command with GNU bash
#!/bin/bash
# author: terry, ben
# tested GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin14)
# FYR (for Mac OS, may need some change for linux)
# second -> ISO8601
date -u -r 1453951368 +%FT%TZ
## ouptput: 2016-01-28T03:22:48Z
# ISO8601 -> second
date -ju -f "%FT%TZ" 2016-01-28T03:22:48Z +%s
## output: 1453951368
@benwei
benwei / install_go_linux.sh
Last active April 5, 2020 07:09
simple script to install golang for Linux Debian or Ubuntu
#!/bin/sh
install_go_linux()
{
sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt update
sudo apt install -y golang-go
ret=$?
if [ $ret -eq 0 ]; then
go version
@benwei
benwei / shell_script_path.sh
Last active March 24, 2020 11:42
get script's location path
t="${0%%`basename $0`}"; cd "$t" ; ABS_PATH=`pwd`
echo $ABS_PATH
@benwei
benwei / list_iwnoise.sh
Created December 6, 2019 07:25
[busybox ash] List signal noise by while loop
i=0 ; while [ $i -lt 5 ] ; do iwconfig wlan0 | grep Noise ; sleep 1 ; i=$((i+1)) ; done
@benwei
benwei / run_iperf_once_a_hour.sh
Created December 6, 2019 01:42
a testing ash script for iperf periodically
#!/bin/sh
IP=$1
if [ "x$IP" = x ]; then
echo "syntax: <ServerIP>"
exit 1
fi
PERIOD=3600
BITS=5M
run_batch_iperf()
@benwei
benwei / start.sh
Last active November 14, 2019 08:24
Logging CPU load by top command per minute with BusyBox command environment
#!/bin/sh
## if you want to run toplog_per_minute.sh in background
## you have to use leading script to put it into backgroud without
## issue of "Stopped (tty output)" Error Message of script that
## stucked on busybox top command
## tested in BusyBox v1.20.2
##################################################################
/bin/sh /mnt/nand/toplog_per_minute.sh &
@benwei
benwei / Example to run script
Last active November 13, 2019 12:24
python script convert string to hex as echo -e command, tested with python 2.7 and 3.5
~$ python2.7 str_to_hex_for_echo_cmd.py
echo -e "testecho_\x21#\x24%\x2a\x5c'\x5c\x22\x21~?<>\x3a| 89920."
~$ python3.5 str_to_hex_for_echo_cmd.py
echo -e "testecho_\x21#\x24%\x2a\x5c'\x5c\x22\x21~?<>\x3a| 89920."
~$ echo -e "testecho_\x21#\x24%\x2a\x5c'\x5c\x22\x21~?<>\x3a| 89920."
testecho_!#$%*\'\"!~?<>:| 89920.
@benwei
benwei / test_result_on_linux_01-abspath-mk
Last active March 21, 2019 14:03
test result of 01-abspath-mk.mk
/build$ make -v
GNU Make 4.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
/build$ lsb_release -a
No LSB modules are available.
current_mk_abspathname := $(abspath $(lastword $(MAKEFILE_LIST)))
current_mk_absdir := $(dir $(current_mk_abspathname))
all:
@echo "Makefile absolute pathname: $(current_mk_abspathname)" ; \
echo "Makefile absolute path: $(current_mk_absdir)"