Skip to content

Instantly share code, notes, and snippets.

@joshgachnang
Last active December 18, 2025 20:43
Show Gist options
  • Select an option

  • Save joshgachnang/2306795 to your computer and use it in GitHub Desktop.

Select an option

Save joshgachnang/2306795 to your computer and use it in GitHub Desktop.
Bash Check Username of User Running Script
if [ "$(whoami)" != "username" ]; then
echo "Script must be run as user: username"
exit 255
fi
@Janovlk
Copy link

Janovlk commented Dec 18, 2025

If you run the script from /etc/crontab the USER variable is not set too. At least in Ubuntu 24.04LTS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment