|
|||||||||
| Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here. |
learn unix and linux commands |
| Tags |
| alias, awk, pkill, sed |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
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 |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
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: Code:
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. |
| Sponsored Links | ||
|
|
|
#3
|
||||
|
||||
|
Code:
alias stop="who |awk '! (/SYSTEM/||/root/) {print \$1}' |xargs pkill -u" |
|
#4
|
||||
|
||||
|
Code:
alias stop="who | sed '/SYSTEM\|root/d' | awk '{print $1}' | xargs -i pkill -u {}" |
| Sponsored Links | ||
|
|
![]() |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Alias setting in Solaris | jdash.ps | Solaris | 2 | 08-02-2010 06:43 AM |
| First Time Linux(Ubuntu) user, Installing | dwainbar | UNIX for Dummies Questions & Answers | 6 | 06-08-2010 02:09 AM |
| Setting an alias in Redhat | jxh461 | Red Hat | 2 | 05-14-2010 12:59 PM |
| Query regarding alias and setting bash as a default script | VENC22 | UNIX for Dummies Questions & Answers | 1 | 07-13-2005 10:18 AM |
| Setting a boot device alias on Sun hardware | 98_1LE | UNIX for Dummies Questions & Answers | 3 | 04-12-2002 12:09 AM |
|
|