Skip to content

Instantly share code, notes, and snippets.

@jsfaint
jsfaint / ntfsutil.sh
Created November 16, 2014 13:13
Enable/Disable Mac build-in NTFS written. e.g.: ./ntfsutil.sh (m/u) /dev/disk2s1
#!/bin/bash
mount_disk()
{
sudo umount $disk
mkdir ~/Desktop/$diskname
sudo mount_ntfs -o rw,auto,nodev,nobrowse,noowners,noatime $disk ~/Desktop/$diskname
echo "Mount $disk to ~/Desktop/$diskname"
open ~/Desktop/$diskname
}
@jsfaint
jsfaint / check_space.sh
Created September 14, 2017 02:24
Push message to wechat via serverchan, when disk space threshold is triggered
#!/bin/bash
avail=$(df / | tail -n 1 | awk '{print $4}')
threshold=""
message="硬盘要满啦"
token=""
if [[ ${avail:?} -lt ${threshold:?} ]]; then
curl "https://sc.ftqq.com/${token:?}.send?text=${message:?}"
fi
@jsfaint
jsfaint / hwmon_temp.sh
Created July 11, 2017 09:16
Get hwmon temperature on Linux via sysfs
#!/bin/bash
hwmon_sysfs="/sys/class/hwmon"
list=$(find "$hwmon_sysfs"/*)
for i in $list; do
if [ -e "$i/name" ]; then
sensor="$i"
else
@jsfaint
jsfaint / mem_chk.sh
Created April 12, 2017 10:07
Monitor the memory usage of given process
#!/bin/bash
# Configure by yourself
procname="cagent"
duration=10
usage()
{
echo "$0 {process name} {duration}"
echo "By default:"
@jsfaint
jsfaint / nutstore_dav.sh
Created March 31, 2017 03:24
Mount jianguoyun with davfs2 via webdav
#!/bin/bash
MOUNTPOINT="$HOME/Nutstore"
sudo mount -t davfs https://dav.jianguoyun.com/dav/ "$MOUNTPOINT"
@jsfaint
jsfaint / lanconf.exp
Created March 24, 2017 08:04
Control lanconf with expect
#!/usr/bin/env expect
set timeout 6
set send_slow {1 .1}
spawn ./lanconf32 textmode
expect {
"Press any key to continue." {send -s " ";}
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
void sig_handler(int signo)
{
printf("Signal %d", signo);
exit(1);
}
@jsfaint
jsfaint / auto_sys_inst.sh
Created March 24, 2017 07:47
Build a live usb disk from rootfs.tgz
#!/bin/bash -
###############################################################################
# FILENAME:
# auto_sys_inst.sh
#
# DESCRIPTION:
# Build a live usb disk from rootfs.tgz
#
# REVISION(MM/DD/YYYY):
# 11/22/2011 jia.sui(jia.sui@advantech.com.cn)
@jsfaint
jsfaint / rpm_file.sh
Created March 24, 2017 07:46
Get type and RPM owner of files under a given path.
#!/bin/bash
# -----------------------------------------------
#
# rpm_file.sh
#
# Description: Get type and RPM owner of files under a given path.
#
# usage:
# ./rpm_file.sh [PATH]
# param:
@jsfaint
jsfaint / update_git.sh
Created March 22, 2017 05:09
Update git for CentOS, build from source
#!/bin/bash
[ -z $1 ] && echo "Missging git src path" && exit 1
git_src=$1
cd $git_src
make prefix=/usr
sudo make prefix=/usr install