In Linux (Mint / Ubuntu), I can create cronjobs for each user individually. Is there any way, I can find out the name of the user against whome the cronjob is running. I want to get the username of cronjob owner in a shell script which is going to cron'd...
Get owner / user of a cronjob
shell;cron
Get the script's ownerOn any system with as stat that is compatible with modern GNU stat, the user ID of the owner of the script is:stat -c %u $0The user name of the owner of the script is:stat -c %U $0In general on linux, stat -c %U file returns the owner of file.  We substitute in $0 because that variable typically contains the name of current script file.Getting effective user ID of the user running the scriptTo get the effective user ID number of the user running a script, use id -u:$ id -u1001To save it in a variable$ uid=$(id -u)$ echo $uid1001If the script is running under bash, then the effective user ID is stored in the shell variable EUID:$ echo $EUID1001On many systems, the default is for cronjobs to run under dash which does not support EUID.  Thus, it is safer and more reliable to use id -u as shown above.Use the -n option in addition to the -u option to get the user name:$ id -unjohn1024