Skip to content

Instantly share code, notes, and snippets.

View zipizap's full-sized avatar

zipizap

View GitHub Profile
#Become user_x, with a login environment
su - user_x
# 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".
@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
sudo adduser user_x group_z
# and now logout/relogin for changes to take effect
# 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")
#
[[ "hello" =~ ^h.[a-z]{2,3}[^[:digit:][:alpha:]]$ ]] && echo "match"
YYYYMMDDhhmmss=$(date +%Y%m%d%H%M%S)
echo $YYYYMMDDhhmmss
# will output 20120604164021
#exit if user is not root
[ "$(id -u)" != "0" ] && { echo "Must be run as root! Aborting"; exit 1;}
function shw_grey { echo -e '\033[1;30m'"$1"'\033[0m'; }
function shw_norm { echo "$1"; }
function shw_info { echo -e '\033[1;34m'"$1"'\033[0m'; }
function shw_warn { echo -e '\033[1;33m'"$1"'\033[0m'; }
function shw_err { echo -e '\033[1;31mERROR: '"$1"'\033[0m'; }
shw_grey "Blablabla nothing interesting..."
shw_norm "I reclaim some attention, but still within normality"
shw_info "I'm an info message - I stand out"
shw_warn "We must fix our economic system"
$ sudo visudo
#add the following to the end of the file:
#allow user "zipizap" to use "sudo /usr/bin/aptitude" without asking for password
zipizap ALL = NOPASSWD: /usr/bin/aptitude
#save and close the edited file