Visit Our UNIX and Linux User Community


Setting alias for a user - Linux ubuntu


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Setting alias for a user - Linux ubuntu
# 1  
Old 08-20-2010
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

# 2  
Old 08-20-2010
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.
# 3  
Old 08-21-2010
Code:
alias stop="who |awk '! (/SYSTEM/||/root/) {print \$1}' |xargs pkill -u"

# 4  
Old 08-21-2010
Code:
alias stop="who | sed '/SYSTEM\|root/d' | awk '{print $1}' | xargs -i pkill -u {}"


Previous Thread | Next Thread
Test Your Knowledge in Computers #157
Difficulty: Easy
The US Department of Defense declared TCP/IP as the standard for all military computer networking in March 1982,
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Setting alias (quotes, acutes)

Hello, I'd like to have an alias to view some processes sorted: I have:ps -ef | grep pmon | awk -F" " '{ print $8" "$0 }' | sort | cut -d" " -f2- | grep -v "grep pmon" It doesn't work, however, if I put it as alias because on acutes insize awk:alias pmon='ps -ef | grep pmon | awk -F" " '{ print... (4 Replies)
Discussion started by: JackK
4 Replies

2. Solaris

Is there a difference between setting a user as nologin and setting it as a role?

Trying to figure out the best method of security for oracle user accounts. In Solaris 10 they are set as regular users but have nologin set forcing the dev's to login as themselves and then su to the oracle users. In Solaris11 we have the option of making it a role because RBAC is enabled but... (1 Reply)
Discussion started by: os2mac
1 Replies

3. Shell Programming and Scripting

alias setting

I want to set an alias to connect to sqlplus and also run a command while it it logs in. How can I do that? (4 Replies)
Discussion started by: som.nitk
4 Replies

4. UNIX for Dummies Questions & Answers

Setting alias with echoing embedded $ sign

I tried to set up some alias in my .profile to save typing. One of the alais i tried to set up is alais test='echo 123$acct54679abc' But when I typed in test in the command line. The echo only dispaly 123 and truncated all the string starting from the $ sign. Is there any way to display the... (6 Replies)
Discussion started by: oht
6 Replies

5. Linux

How to run User-mode Linux installed with synaptic package manager in Ubuntu 10.10

I have installed user-mode linux kernel in Ubuntu 10.10 with the help of Synaptic package manager. But I'm not getting how to run it. If we install it manually, we've to run it using the executable binary file. But here, I'm unable to locate any such file. Please help.... Thanking You.... ... (0 Replies)
Discussion started by: rohitadeshmukh1
0 Replies

6. Solaris

Alias setting in Solaris

Hi All, I need some information on 'Alias' setting in SUN SOLARIS.:confused: Q1. I want to know how can i set my alias here. Q2. How to view all set 'ALIAS' for me. (say /home/jdash user) Q3. Can i modify the set 'Alias' for me or for whole environment. Q4. Is Alias setting can be change... (2 Replies)
Discussion started by: jdash.ps
2 Replies

7. UNIX for Dummies Questions & Answers

First Time Linux(Ubuntu) user, Installing

I want to install ubuntu on a seperate hard drive. I have two 500gb sata drives with XP on sata 0,0 and like to install ubuntu on the other sata 1,1. A few questions: Will this work? Can I unplug the XP drive and boot up with ubuntu to 1,1? If that works, how can I boot to... (6 Replies)
Discussion started by: dwainbar
6 Replies

8. Red Hat

Setting an alias in Redhat

Hi Everyone, I am trying to set up alias the only way I now how, buy making entry into .bashrc file. The entry I made is alias ll='ls -lrt' It is not working as I expect. When I enter "alias" at the command line I get the following. $ alias alias l.='ls -d .* --color=tty' alias... (2 Replies)
Discussion started by: jxh461
2 Replies

9. UNIX for Dummies Questions & Answers

Query regarding alias and setting bash as a default script

Hi All, I am setting bash as my working shell in my .profile file. So I have written a line : bash as the list line in my .profile I want to use alias as follows: alias me='who am i' When i log in, as expeced I enter the bash shell but alias doesn't work. Is it because the alias is defined... (1 Reply)
Discussion started by: VENC22
1 Replies

10. UNIX for Dummies Questions & Answers

Setting a boot device alias on Sun hardware

I watched this done a long time ago, but cannot find it anywhere. I need to alias the boot device "disk" to /sbus@7,0/QLGC,isp@0,10000/sd@c,0 I think I need to set "use-nvramrc?" to true, and then create an alias within the nvramrc to point disk to the boot disk, but this is the step I cannot... (3 Replies)
Discussion started by: 98_1LE
3 Replies

Featured Tech Videos