Skip to content

Instantly share code, notes, and snippets.

View zipizap's full-sized avatar

zipizap

View GitHub Profile
#exit if user is not root
[ "$(id -u)" != "0" ] && { echo "Must be run as root! Aborting"; exit 1;}
YYYYMMDDhhmmss=$(date +%Y%m%d%H%M%S)
echo $YYYYMMDDhhmmss
# will output 20120604164021
[[ "hello" =~ ^h.[a-z]{2,3}[^[:digit:][:alpha:]]$ ]] && echo "match"
# I want to *snoop* the stdout(1) and stderr(2) of the process named 'ntfsresize'
# (run as root)
strace -p $(pidof "ntfsresize") -e trace=write 2>&1 | grep 'write(1'
# Explanation:
#
# -p $(pidof "ntfsresize")
# Apply strace to the process named "ntfsresize"
# If you want to trace a bash script, use instead $(pidof -x "script-name.sh")
#
sudo adduser user_x group_z
# and now logout/relogin for changes to take effect
@zipizap
zipizap / vps.sh
Last active March 23, 2024 16:24
#PROLOGUE: all this should be run as root, otherwise stated
#update && upgrade:
apt-get update && apt-get upgrade -y
#create a new user
adduser user_x
#create group admin (funny enough, it does not exist, although its accounted in the /etc/sudoers file):
addgroup --system admin
# See "man 5 crontab"
#
# Instead of the first five fields, one of eight special strings may appear:
# string meaning
# ------ -------
# @reboot Run once, at startup.
# @yearly Run once a year, "0 0 1 1 *".
# @annually (same as @yearly)
# @monthly Run once a month, "0 0 1 * *".
# @weekly Run once a week, "0 0 * * 0".
#Become user_x, with a login environment
su - user_x
#Run command as user_x, within a login environment
sudo -u user_x -i echo This is my command and should not be quoted
#Add this to /etc/fstab
/dev/sda1 /Windows ntfs-3g defaults,uid=1000,gid=1000,dmask=027,fmask=137 0 0