bash 脚本执行时自动切换到root用户
#!/usr/bin/env bash
# Author=liy36
export PS4='\[\e[35m\]+ $(basename $0):${FUNCNAME}:$LINENO: \[\e[0m\]'
if [ "$(id -u)" -ne 0 ];then
echo "Switch to the root user execute $0 $@"
exec sudo bash "$0" "$@"
exit 0
fi
echo "I'm running on $(id -u)."
echo "args ${@}"