Fetch PID


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Fetch PID
# 8  
Old 07-14-2011
Sorry Buddy...its

Code:
if [ -f "${Filename}"-a "$( fuser "${filename}" 2>/dev/null )" = "" ]

It dosen't work even when i have opend the same file.....
# 9  
Old 07-14-2011
what is ${Filename} and ${filename}

did u execute the command fuser filename manually ?
# 10  
Old 07-14-2011
Hi..

Code:
 
#!/bin/bash
cd /sapphire/limit
array=(`ls`)
len=${#array[*]}
echo "The array has $len members"
i=0
while [ $i -lt $len ];
do
        if [ -f "${array[i]}" -a "$( fuser "${array[i]}" 2>/dev/null )" = "" ]
        then 
        echo "File is not open"
        else
        echo "File is open"
        fi
let i++
done

Bit i get File is not opene even when its open....i tried manually fuser {filename} still no output
# 11  
Old 07-14-2011
Code:
#!/bin/bash
cd /sapphire/limit
array=(`ls`)
len=${#array[*]}
echo "The array has $len members"
i=0
while [ $i -lt $len ];
do
        ps -ef | grep -v grep | grep ${array[i]} > /dev/null 2>&1
        if [ "$?" -eq "0" ]
        #if [ -f "${array[i]}" -a "$( fuser "${array[i]}" 2>/dev/null )" = "" ]
        then 
         echo "File is open"
        else
     echo "File is not open"
        fi
let i++
done

# 12  
Old 07-14-2011
Code:
#!/bin/bash

filename=/home/file.txt
pid=`ps -ef|grep file.txt|grep -v grep |awk '{ print $2}'`

echo "Pid of file $filename is $pid"

if [ -z "$pid" ]
then
echo "File is closed"
else
echo "file is open"
fi

# 13  
Old 07-14-2011
Quote:
Originally Posted by asheshrocky
Hi Buddy,
...
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?
I think vi tricked you here. After the file is read into the buffer vi closes the original file and has only the (hidden) swapfile open . Try less or pg instead of vi.
# 14  
Old 07-14-2011
Thanks guys......

I hope the script work fine after using the above said suggestions...

Code:
 
#!/bin/sh
HOST='test'
USER='testuser'
PASSWD='test_passwd'
cd /sapp/limit
array=(`ls`)
len=${#array[*]}
echo "The array has $len members"
i=0
while [ $i -lt $len ];
do
        ps -ef | grep -v grep | grep ${array[i]} > /dev/null 2>&1
        if [ "$?" -eq "0" ]
        then
            echo "${array[i]} is been accessed"
        else
           new=${array[i]%.limit.dis}.data.dis
             if [ -f /sapp/data/$new ]
             then
             echo "Matching Data File found"
             ps -ef | grep -v grep | grep ${new} > /dev/null 2>&1
                 if [ "$?" -eq "0" ]
                 then
                     echo "${new} is been accessed"
                 else
                     echo "FTP over the Files,Start FTP"
                     ftp -nv <<EOF
                     open $HOST
                     user $USER $PASSWD
                     cd sapp/ftp/Limit
                     binary
                     mput ${array[i]}
                     227
                     cd ../Data
                     mput ${new}
                     227
EOF
                     echo "Files are transfered sucessfully"
                     mv `pwd`/$array[i] ../ARCHIVES/Limit
                     mv ../Data/$new ../ARCHIVES/Data
                     echo "Files Moved to ARCHIVES"
                 fi
            else
              echo "No Matching data File is found"
            fi
        fi
let i++
done

Let me know if any optimization is required.....

Last edited by asheshrocky; 07-14-2011 at 10:08 PM..
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