Sponsored Content
Top Forums Shell Programming and Scripting Output of ps + awk in a variable to get PID Post 302296115 by Digby on Tuesday 10th of March 2009 11:49:35 AM
Old 03-10-2009
What kind of script is it? It's probably not that same as the shell you are working from.

Your command wouldn't work in my console. But it did when I changed it to this.

Code:
set a = `ps aux | awk '/test5/ && \!/awk/ {print $2}'`


Last edited by Digby; 03-10-2009 at 12:54 PM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

how to output awk to a variable

Hi folks, I am wondering how to output awk back to a variable. I am new to Unix/Linux. I am trying to get rid of a decimal number and put the output back in a variable for further use in the script. here is how I used awk: var=$1 echo $var |awk '{print $1 *100}' | $var echo $var this... (4 Replies)
Discussion started by: bashirpopal
4 Replies

2. UNIX for Dummies Questions & Answers

Set a variable from awk output

I have a file which I am processing using awk to spit out the following: export CLIENT=1 ; export USER=1 ; export METABASE=1 ; export TASK=1 ; export TOTAL=3 What i want to do now is execute that within the script so those variables are available to other commands. I've tried piping the... (3 Replies)
Discussion started by: Cranie
3 Replies

3. UNIX for Dummies Questions & Answers

Need to get pid of a process and have to store the pid in a variable

Hi, I need to get the pid of a process and have to store the pid in a variable and i want to use this value(pid) of the variable for some process. Please can anyone tell me how to get the pid of a process and store it in a variable. please help me on this. Thanks in advance, Amudha (7 Replies)
Discussion started by: samudha
7 Replies

4. Shell Programming and Scripting

AWK Output into a variable

Hi I am trying to store the output of awk into a variable in a shell script. I can run it successfully from the command line but not from a ksh shell script. ls -al test.txt | grep -v grep | awk '{print $1}' returns -rw-r--r-- #!/bin/ksh perm=$(`ls -al test.txt | grep -v grep | awk... (2 Replies)
Discussion started by: mace_560
2 Replies

5. Shell Programming and Scripting

awk output in a variable

Not sure why it is not working the following : set -- $@ stype ="a" for shell_args in "$@" do $stype=` awk '{print substr ("'"$shell_args"'", 0, 3)}' ` echo $stype done Thank you (5 Replies)
Discussion started by: andaluzia
5 Replies

6. Shell Programming and Scripting

using awk for setting variable but change the output of this variable within awk

Hi all, Hope someone can help me out here. I have this BASH script (see below) My problem lies with the variable path. The output of the command find will give me several fields. The 9th field is the path. I want to captured that and the I want to filter this to a specific level. The... (6 Replies)
Discussion started by: Cowardly
6 Replies

7. Shell Programming and Scripting

help on awk---- need to assign the output of awk to a variable

hi i want to find the size of a folder and assign it to a variable and then compare if it is greater than 1 gb. i am doin this script, but it is throwing error.... #!/bin/ksh cd . | du -s | size = awk '{print $1}' if size >= 112000 then echo size high fi ERROR : (4 Replies)
Discussion started by: Nithz
4 Replies

8. Shell Programming and Scripting

awk question : system output to awk variable.

Hi Experts, I am trying to get system output to capture inside awk , but not working: Please advise if this is possible : I am trying something like this but not working, the output is coming wrong: echo "" | awk '{d=system ("date") ; print "Current date is:" , d }' Thanks, (5 Replies)
Discussion started by: rveri
5 Replies

9. Shell Programming and Scripting

How to read the variable from awk output?

I am reading an xml file with date tag as <Date>Default</Date> using the below command. Dt=$(awk -F'' '/<Date>/{print $3}' /home/test/try.xml and getting the value from the xml file stored in this variable "Dt" echo $Dt gives me a value. Dt=Default. Now according to my requirement, If... (2 Replies)
Discussion started by: Saidul
2 Replies

10. UNIX for Beginners Questions & Answers

Using variable output in awk

Hi, I am trying to use variable output in awk to append a string to a word in a line. But that is not happening. Could you please help me on this. YouTube Video Tutorial: How to Use Code Tags and Format Posts @UNIX.com The below is the code #!/bin/ksh set -x src=/users/oracle/Temp... (2 Replies)
Discussion started by: pvmanikandan
2 Replies
SHLOCK(1)						    BSD General Commands Manual 						 SHLOCK(1)

NAME
shlock -- create or verify a lock file for shell scripts SYNOPSIS
shlock [-du] [-p PID] -f lockfile DESCRIPTION
The shlock command can create or verify a lock file on behalf of a shell or other script program. When it attempts to create a lock file, if one already exists, shlock verifies that it is or is not valid. If valid, shlock will exit with a non-zero exit code. If invalid, shlock will remove the lock file, and create a new one. shlock uses the link(2) system call to make the final target lock file, which is an atomic operation (i.e. "dot locking", so named for this mechanism's original use for locking system mailboxes). It puts the process ID ("PID") from the command line into the requested lock file. shlock verifies that an extant lock file is still valid by using kill(2) with a zero signal to check for the existence of the process that holds the lock. The -d option causes shlock to be verbose about what it is doing. The -f argument with lockfile is always required. The -p option with PID is given when the program is to create a lock file; when absent, shlock will simply check for the validity of the lock file. The -u option causes shlock to read and write the PID as a binary pid_t, instead of as ASCII, to be compatible with the locks created by UUCP. EXIT STATUS
A zero exit code indicates a valid lock file. EXAMPLES
BOURNE SHELL #!/bin/sh lckfile=/tmp/foo.lock if shlock -f ${lckfile} -p $$ then # do what required the lock rm ${lckfile} else echo Lock ${lckfile} already held by `cat ${lckfile}` fi C SHELL #!/bin/csh -f set lckfile=/tmp/foo.lock shlock -f ${lckfile} -p $$ if ($status == 0) then # do what required the lock rm ${lckfile} else echo Lock ${lckfile} already held by `cat ${lckfile}` endif The examples assume that the file system where the lock file is to be created is writable by the user, and has space available. HISTORY
shlock was written for the first Network News Transfer Protocol (NNTP) software distribution, released in March 1986. The algorithm was sug- gested by Peter Honeyman, from work he did on HoneyDanBer UUCP. AUTHORS
Erik E. Fair <fair@clock.org> BUGS
Does not work on NFS or other network file system on different systems because the disparate systems have disjoint PID spaces. Cannot handle the case where a lock file was not deleted, the process that created it has exited, and the system has created a new process with the same PID as in the dead lock file. The lock file will appear to be valid even though the process is unrelated to the one that cre- ated the lock in the first place. Always remove your lock files after you're done. BSD
June 29, 1997 BSD
All times are GMT -4. The time now is 06:06 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy