Lunar Mushrooms
Lunar Mushrooms

Reputation: 8958

Getting username while cron job is invoked

As root, I can add user specific cron job by crontab -u user1 -e . There I can mention a shell script say runbackup.sh to get executed.

Since runbackup.sh script is used for many users, the script need to know the username (here user1) to do some user specific actions.

How the runbackup.sh could get the username when cron job invokes it?

Thanks,

Upvotes: 6

Views: 3216

Answers (1)

shiwenlu518
shiwenlu518

Reputation: 466

Use "whoami" in your script runbackup.sh will shows who is excuting the shell.

Every user's cron job will start a shell process. So Every whoami show the running users' name.

Pls note that: All Users have permition to files mentioned in runbackup.sh.

Upvotes: 10

Related Questions