I am in a UNIX system administration course at school and have to generate a Cron job that does the following:
- Queries the system each hour to find
out who is logged in. - Mails the result to my email account.
I know that the actual crontab will look like the following:
# Check to see who is logged in every hour.
MAILTO="me@email.com"
0 * * * * root /tmp/loggedin.sh
OR
# Check to see who is logged in every hour.
MAILTO="me@email.com"
@hourly /tmp/loggedin.sh
But I have been Googling for some time and have been unable to find any examples of what exactly the .sh file should look like. I know it starts with:
#!/bin/bash
# Shell script to see who is logged in, to be run every hour.
And I have no idea what else to put in there. Any help is greatly appreciated!
I think
whoshould do the trick. It will show you a list of all the users that are logged in to the system at a time. You can write this to a file and then have it mailed to you.wwould get you what the people logged in are currently doing.So, the script would look like:
${HOME}refers to your home directory. On the command prompt,echo $HOMEshould give you your home directory. The output of the commandwhoandwwill get redirected to the filesusersLoggedIn.txtandwhattLoggedInUsersAreDoing.txtwithin your home directory. You can, of course, change the directory and file names to which you want this data to be written.HTH,
Sriram