Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

errors using 'who' command

Status
Not open for further replies.

jlaw10

Technical User
Jul 28, 2005
54
0
0
US
Attempting to monitor root access w/ the following command -
[root@prematics32 ~]# echo 'ALERT - Root Shell Access on:' `date` `who` mail -s "Alert: Root Access from `who cut -d"(" -f2 cut -d")" -f1`" user@example.com

Receive the following error:
who: invalid option -- (
Try `who --help' for more information.
ALERT - Root Shell Access on: Fri Aug 20 13:28:45 EDT 2010 micore pts/1 Aug 20 11:03 (172.16.192.82) mail -s Alert: Root Access from user@example.com

Does anyone know what 'who' parameter is triggering this error and what the proper syntax should be?
 
It looks like your commands are strung together. Instead of "who cut -d", try for example, "who | cut -d" etc.

 
Still receive same errors w/ all recommended options:

[root@prematics31 ~]# echo 'ALERT - Root Shell Access on:' `date` `who` mail -s "Alert: Root Access from `who cut -d -f1`" jason.outlaw@micoresolutions.com
who: invalid option -- f
Try `who --help' for more information.
ALERT - Root Shell Access on: Sun Aug 22 09:34:13 EDT 2010 micore pts/1 Aug 22 09:31 (172.16.200.90) mail -s Alert: Root Access from jason.outlaw@micoresolutions.com
[root@prematics31 ~]# echo 'ALERT - Root Shell Access on:' `date` `who` mail -s "Alert: Root Access from `who cut -f2 cut -d -f1`" jason.outlaw@micoresolutions.com
who: invalid option -- f
Try `who --help' for more information.
ALERT - Root Shell Access on: Sun Aug 22 09:34:42 EDT 2010 micore pts/1 Aug 22 09:31 (172.16.200.90) mail -s Alert: Root Access from jason.outlaw@micoresolutions.com


[root@prematics31 ~]# echo 'ALERT - Root Shell Access on:' `date` `who` mail -s "Alert: Root Access from `who | cut -d"(" -f2 cut -d")" -f1`" jason.outlaw@micoresolutions.com
cut: only one type of list may be specified
Try `cut --help' for more information.
ALERT - Root Shell Access on: Sun Aug 22 09:35:46 EDT 2010 micore pts/1 Aug 22 09:31 (172.16.200.90) mail -s Alert: Root Access from jason.outlaw@micoresolutions.com



 
I think you're following bad advice there in the first place; the output of those commands is going to be a complete mess by the time it makes it into an email anyway, especially when there are multiple users logged on to the system (i.e. multiple lines of who output all squashed up on one line).

I would rearrange it like this:

Code:
(
        echo "ALERT - Root Shell Access on: $(date)"
        echo
        who
) | mail -s "Alert: Root Access from $(who am i | cut -f2 -d'(' | cut -f1 -d ')')" jason.outlaw@example.com
)


Annihilannic.
 
Annihilannic...the email output is perfect just one small detail and then this issue will be closed. I still received this error at at the command line (despite email results as expected):

[root@prematics32 ~]# )
-bash: syntax error near unexpected token `)'

 
Try this -

Code:
echo "ALERT - Root Shell Access on: $(date)"
        echo
        who | mail -s "Alert: Root Access from $(who am i | cut -f2 -d'(' | cut -f1 -d ')')" jason.outlaw@example.com
 
Or just remove the extra ")" at the very end of the script... not sure where I got that one from!

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top