Sponsored Content
Full Discussion: ps l
Top Forums UNIX for Dummies Questions & Answers ps l Post 32190 by criglerj on Wednesday 20th of November 2002 08:57:03 AM
Old 11-20-2002
Save a process

Quote:
Originally posted by mphartley
When I kick off a script I then need to check whether or not it is running (in another sesssion) by another script.

ps -fu$USER | grep scriptname.sh | grep -v grep |wc -l
As Perderabo noted separately, your shell probably forked.

Another hint: You can save a process --- and time unless $USER has thousands of processes running but maybe even then --- this way (idea from Essential System Administration by Aeleen Frisch, 2nd edition, but I think a 3rd is out now):
Code:
ps -fu$USER | grep '[s]criptname.sh' |wc -l

Why this works is left as an exercise for the reader ... Smilie
 
ZGREP(1)						      General Commands Manual							  ZGREP(1)

NAME
zgrep - search possibly compressed files for a regular expression SYNOPSIS
zgrep [ grep_options ] [ -e ] pattern filename... DESCRIPTION
Zgrep invokes grep on compressed or gzipped files. These grep options will cause zgrep to terminate with an error code: (-[drRzZ]|--di*|--exc*|--inc*|--rec*|--nu*). All other options specified are passed directly to grep. If no file is specified, then the standard input is decompressed if necessary and fed to grep. Otherwise the given files are uncompressed if necessary and fed to grep. If the GREP environment variable is set, zgrep uses it as the grep program to be invoked. EXIT CODE
2 - An option that is not supported was specified. AUTHOR
Charles Levert (charles@comm.polymtl.ca) SEE ALSO
grep(1), gzexe(1), gzip(1), zdiff(1), zforce(1), zmore(1), znew(1) ZGREP(1)
All times are GMT -4. The time now is 06:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy