Fetch PID


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Fetch PID
# 1  
Old 07-14-2011
Fetch PID

Hi All,

i get this output when i do PS UX

Code:
tdntp  9263  0.0  0.0  98464  3200 pts/1    S+   14:16   0:00 vim FAB1_600015_CONRAD.A0_7XYZ12345.000_LT-SWET.01_LTPA25L_

I want to get the PID of certain specefic filename.

so i tried

Code:
ps ux | pgrep FAB1_600015_CONRAD.A0_7XYZ12345.000_LT-SWET.01_LTPA25L_

But still i get no PID as the command is preceded by "vim".....is there any way out to get PID of only Filename.
# 2  
Old 07-14-2011
what you mean by pid of only filename ?
# 3  
Old 07-14-2011
Hi Buddy,

I am writing a script to FTP out files from server 1 to server 2.These files are generated by another Java application running in server 1.

Before FTP out these files i want to check if these files are complete or it is still been access by any other process (Could be move or copy by java application).

So i thought of doing PS UX | pgrep Filename

But this always returns null as the output from PS UX will be

Code:
mv FAB1_600015_CONRAD.A0_7XYZ12345.000_LT-SWET.01_LTPA25L_
 or
cp FAB1_600015_CONRAD.A0_7XYZ12345.000_LT-SWET.01_LTPA25L_

So i want to just check grep for FAB1_600015_CONRAD.A0_7XYZ12345.000_LT-SWET.01_LTPA25L_ by not considering the command it is used with.
# 4  
Old 07-14-2011
you can simply check like below

Code:
 
ps -ef | grep -v grep | grep "FAB1_600015_CONRAD.A0_7XYZ12345.000_LT-SWET.01_LTPA25L_"
[ "$?" -eq "0" ] && echo "Safe to FTP" || echo "Some commands accessing the file"

This User Gave Thanks to itkamaraj For This Post:
# 5  
Old 07-14-2011
Use fuser or lsof commands to check if the file is open by another program
# 6  
Old 07-14-2011
Hi Buddy,

I have tried using smething like

Code:
if [ -f "$Filename" -a "$( fuser "$filename}" 2>/dev/null )" = "" ]
then 
echo "File is closed"
else
echo "file is open"

But i found this command always gives File is closed even when i open the file with "vi"....So i thought of going for other option like PS UX....

Any suggestions?
# 7  
Old 07-14-2011
Is it typo ?

"$( fuser "$filename}" 2>/dev/null )" = ""
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Looping and fetch few rows

Could you please let me know how to start coding for the below requirement, based on your inputs I will start writing the code: InputFile.txt #Comment1 #Comment2 #Comment3 StartJob Job "Job1" Date "2014-05-14" Column='records ( column1 char(100); column2 varchar2(10); ... (2 Replies)
Discussion started by: unme
2 Replies

2. Shell Programming and Scripting

Fetch Valid String

Hi All, How to fetch the particular row based on my search command. For example Source Column Column A Column B 001,56123456 002,57123456 003,123456 Expected Output: 003,123456 To get this output I tried below mentioned function grep '123456' filename.txt (4 Replies)
Discussion started by: suresh_target
4 Replies

3. Shell Programming and Scripting

Help Need to fetch the required data

Hi Guys, Am in need of your help one more time on my real data. I have a file which contains more than thousand lines of data Live data shown for 4 iterations. We have more than thousand lines of data:- -------------------------------------------------------------------------- ... (4 Replies)
Discussion started by: rocky2013
4 Replies

4. Shell Programming and Scripting

Fetch the value from Here Document

I have code like var="1" echo << EOF export `var="2"` EOF echo $var The value of var is printed here is 1 but it should be 2 Any error there? ---------- Post updated at 11:44 AM ---------- Previous update was at 10:33 AM ---------- Also tried var="1" echo var << EOF echo... (1 Reply)
Discussion started by: adisky123
1 Replies

5. UNIX for Dummies Questions & Answers

how to fetch data in unix

Hi All, I have a file with the below data as shown. A|2|20120430 B|EMP|NAME|DEPT C|12|SARC|01 C|23||ASDD|02 D|END OF FILE I want to fetch only the records that contains C|, what is unix command to fetch this data. Thanks (5 Replies)
Discussion started by: halpavan2
5 Replies

6. UNIX for Dummies Questions & Answers

fetch Variable value

Hi Guys, I have written a script that declares all the variables and its values in a conf file. Now i use a variable whose value i need to change it in one of the sub-file that is used in the script. In the startup file i want to print or check its value. The value get changed and printed... (5 Replies)
Discussion started by: Swapna173
5 Replies

7. 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

8. Shell Programming and Scripting

KILL PID, intern should kill another PID.

Hi All, In my project i have two process runs in the back end. Once i start my project, and execute the command ps, i get below output: PID TTY TIME CMD 9086 pts/1 0:00 ksh 9241 pts/1 0:02 java 9240 pts/1 0:00 shell_script_bg java with 9241 PID is the main... (4 Replies)
Discussion started by: rkrgarlapati
4 Replies

9. UNIX for Dummies Questions & Answers

Session PID & socket connection pid

1. If I use an software application(which connects to the database in the server) in my local pc, how many PID should be registered? Would there be PID for the session and another PID for socket connection? 2. I noticed (through netstat) that when I logged in using the my software application,... (1 Reply)
Discussion started by: pcx26
1 Replies

10. Programming

printing ppid,child pid,pid

question: for the below program i just printed the value for pid, child pid and parent pid why does it give me 6 values? i assume ppid is 28086 but can't figure out why there are 5 values printed instead of just two! can someone comment on that! #include<stdio.h> #define DIM 8 int... (3 Replies)
Discussion started by: a25khan
3 Replies
Login or Register to Ask a Question