- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- alias in ksh
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2003 02:58 PM
02-24-2003 02:58 PM
psg oracle (would list all procs which has oracle word in them)
psg http (all procs with http word in them)
alias=`ps -ef|grep -i |grep -v grep'
I was able to do the above in csh by substituting with \!*
What is the corresponding string for ksh?
Thanks in advance
...Manjeet
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2003 03:00 PM
02-24-2003 03:00 PM
Re: alias in ksh
Sorry for the typo!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2003 03:34 PM
02-24-2003 03:34 PM
Re: alias in ksh
example-
function psg {ps -ef | grep $1 | grep -v "grep"}
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2003 04:27 PM
02-24-2003 04:27 PM
Re: alias in ksh
Should be
ps -ef | grep -i $1 | grep -v grep
$X where X is numeric are argument vars.
$0 = command
$1 = 1st argument
$2 = 2nd argument
etc.
Rgds,
Jeff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2003 04:31 PM
02-24-2003 04:31 PM
Re: alias in ksh
ps -ef | grep -i -e $1 -e $2 -e $3 ....etc | grep -v grep
And then you could do
psg oracle http java
and get all procs with any of those.
Jeff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2003 09:17 PM
02-24-2003 09:17 PM
Re: alias in ksh
ps -f -u oracle
Or to search for a specific process (and not locate processes with unrelated strings), use the -C option:
UNIX95= ps -f -C sh
which will NOT find ksh like grep does.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2003 01:18 AM
02-25-2003 01:18 AM
Re: alias in ksh
I do not know how to replace your ??? of csh but why not just do ps instead of writting a function. I think ps is given for this purpose.
Use as many standard commands as you can before writting your own functions, otherwise it will only complicate things further.
hope this helps..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2003 07:56 AM
02-25-2003 07:56 AM
Re: alias in ksh
How would I make use of this function? Do I include it in a script?
psg is just an example; I have many aliases defined that way in my .cshrc. That will mean writing scripts for all of them!
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2003 07:59 AM
02-25-2003 07:59 AM
Re: alias in ksh
$1 doesn't work in alias.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2003 08:05 AM
02-25-2003 08:05 AM
Re: alias in ksh
Its not a single alias that I am trying to work. I have lot many and writing scripts for them may be an overkill. But so far, what I am learning from user-community is that ksh doesn't have that feature.
Thanks for the tip for -C flag. How would I use it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2003 08:13 AM
02-25-2003 08:13 AM
Re: alias in ksh
Good catch! It should be forward tick and not reverse tick as I put in my initial post.
Writing aliases and functions saves time and make things go faster. I would rather type "psg http" than "ps -ef|grep http|grep -v grep" every time I have to look for http procs. Just my personal preference!
:-)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2003 11:01 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2003 11:14 AM
02-25-2003 11:14 AM
Re: alias in ksh
If you are trying to make alias definitions that are interchangable between the 2 shells, then I think you won't be able to do that.
If you are converting over to "ksh" and dropping "csh" as your primary shell, then you can convert all your aliases to functions, place them in ".profile" to set them at login.
It is pretty easy to convert the alias to a function. example-
alias psg='ps -ef | grep -i | grep -v grep'
becomes
function psg {ps -ef | grep -i $1 | grep -v }
You could build these functions by replacting the following-
"alias" with "function"
"='" with "{"
trailing "'" with "}".
If you have a lot, you could use sed or awk or perl to build up .profile.
Aliases under ksh only do "word" substitutions at the beginning of a command. Their is no equivalent .
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2003 03:17 PM
02-25-2003 03:17 PM
Re: alias in ksh
Thanks. The function works the following way -
psg() {
ps -ef|grep -i $1|grep -v grep
}
I can include my other aliases this way.
Thanks again
...Manjeet
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2003 06:40 PM
02-26-2003 06:40 PM
Re: alias in ksh
UNIX95= ps -f -C sh
The UNIX95= simply defines the variable with a null value (UNIX95 can be anything including null) and in POSIX shells like ksh, the variable assignment can be placed in front of the command. Without UNIX95= then ps doesn't know what to do with -C
The primary advantage of -C is that ps searches the EXACT match of the program name (and not the pathname or username or anything else). Thus:
UNIX95= ps -f -C java
will not find any users with java in their name (like java or hotjava) nor will it find processes with a pathname such as /opt/java/bin/java3) because it looks just at the process name.
-H is pretty nifty when looking for a hierarchy of parents and children, and -o allows you to construct your own version of ps as in:
UNIX95= ps -e -o vsz,pid,args | sort -rn
which shows the resident set size of all prgrams, their PID and the command line, then sorted by VSZ (which is in Kbytes)
Bill Hassell, sysadmin