Setting alias for a user - Linux ubuntu

Hi

i have a user "SYSTEM"
i want to set the below command in his .profile for an alias:

who | awk '{print $1}'| sed '/SYSTEM/d' | sed '/root/d' |xargs -i pkill -u {}

i tried as below:

alias stop = " who | awk '{print $1}'| sed '/SYSTEM/d' | sed '/root/d' |xargs -i pkill -u {}"

whenever i login as this user and type "stop"
i get the below:

pkill: invalid user name: joyce pts/2 Aug 19 00:34 (jm4tvk1.com)
pkill: invalid user name: joyce1 pts/3 Aug 19 00:35 (jm4tvk1.com)

Any idea why this is failing? Also i added this user in /etc/sudoers

The $1 in your awk script is being expanded (probably to nothing) when you set the alias. This results in the awk being "{print}" rather than {print $1} and the whole line from who is being printed.

try escaping the $ with a back-slant:

alias stop="who | awk '{print \$1}'|sed '/SYSTEM/d' | sed '/root/d' |xargs -i pkill -u {}"

which should pass the $1 as is into the alias and then execute it properly. You might also want to pipe your output to sort -u before piping it into xargs on the off chance that a user is logged in more than once.

alias stop="who |awk '! (/SYSTEM/||/root/) {print \$1}' |xargs pkill -u"
alias stop="who | sed '/SYSTEM\|root/d' | awk '{print $1}' | xargs -i pkill -u {}"