The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
substring panknil Shell Programming and Scripting 4 10-01-2007 08:12 AM
How do I Substring ?? Rigger Shell Programming and Scripting 6 04-26-2007 02:26 AM
substring alla.kishore UNIX for Dummies Questions & Answers 8 01-09-2007 02:57 AM
substring using AWK mahabunta UNIX for Dummies Questions & Answers 3 09-19-2006 04:47 PM
substring Anika UNIX for Dummies Questions & Answers 4 09-19-2001 03:10 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-01-2007
varungupta varungupta is offline
Registered User
  
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 206
Exclamation substring ??

I execute command on this file and it gives o/p like this.

COMMAND $ fuser -f /clocal/sanjay/AccessMonitor

/clocal/sanjay/AccessMonitor: 1368322c

To truncate 'c', i used tr -dc "[:digit:]\n" but then it does't give 1368322 as O/P.

Any help ??
  #2 (permalink)  
Old 10-01-2007
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Quote:
Originally Posted by varungupta View Post
I execute command on this file and it gives o/p like this.

COMMAND $ fuser -f /clocal/sanjay/AccessMonitor

/clocal/sanjay/AccessMonitor: 1368322c

To truncate 'c', i used tr -dc "[:digit:]\n" but then it does't give 1368322 as O/P.

Any help ??
What is the input to the tr command ?

For me that tr command works fine.
Code:
[/tmp]$ echo 123abc | tr -dc "[:digit:]\n"
123
[/tmp]$
  #3 (permalink)  
Old 10-01-2007
varungupta varungupta is offline
Registered User
  
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 206
Quote:
Originally Posted by vino View Post
What is the input to the tr command ?

For me that tr command works fine.
Code:
[/tmp]$ echo 123abc | tr -dc "[:digit:]\n"
123
[/tmp]$
pid = ''
fuser -f /clocal/sanjay/AccessMonitor > tempfind.txt
pid = cat tempfind.txt | tr -dc "[:digit:]\n"
echo "$pid"



When prompt I run the above command, it gives....
$ fuser -f /clocal/AccessMonitor
/clocal/AccessMonitor: 1368322c

Now I want the no. (without ant character) into the variable pid (given above).

Any idea ??
  #4 (permalink)  
Old 10-01-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,420
Try :
Code:
pid=`cat tempfind.txt | tr -dc "[:digit:]"`
Or
Code:
pids=`fuser -f "$file_dir" | tr -dc "[:digit:]"`
Jean-Pierre.
  #5 (permalink)  
Old 10-01-2007
varungupta varungupta is offline
Registered User
  
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 206
Arrow Solution please :)

Quote:
Originally Posted by vino View Post
What is the input to the tr command ?

For me that tr command works fine.
Code:
[/tmp]$ echo 123abc | tr -dc "[:digit:]\n"
123
[/tmp]$
Can you rectify problem in the following script ??

MYPATH="/clocal/Sanjay/"
MAIL_RECIPIENTS="abcx@zzz.com"
Subject="File accessed in last few minutes are ::"
>tempmail.txt
>tempfind.txt

## List all the files which one accessed since last 1 min #####

for file_dir in `find $MYPATH -amin -1`
do
### Find out the PID for that files which one been accessed
pid = ''
fuser -f "$file_dir" > tempfind.txt
pid = cat tempfind.txt | tr -dc "[:digit:]\n"

echo "$pid"

### Find out the owner/user name for that Process
### Replace the $access_user_filed with the filed no from the ps -ef
### command
user = `ps -ef | grep -w "$pid" | awk '{ print $1 }'`
echo " $file_dir access by the $user " >> tempmail.txt
done

cat tempmail.txt | mailx -s "$Subject" "$MAIL_RECIPIENTS"
---------------------------------------------------------------------

Once red faced commands will run successfully, means task is achieved.
Now, in variable pid, i am not getting any thing. I want the process no. related to the file accessed, using fuser command. As shown above.

Any help will be appreciable. !!
  #6 (permalink)  
Old 10-01-2007
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Quote:
Originally Posted by varungupta View Post
fuser -f "$file_dir" > tempfind.txt
pid = cat tempfind.txt | tr -dc "[:digit:]\n"


Once red faced commands will run successfully, means task is achieved.
Now, in variable pid, i am not getting any thing. I want the process no. related to the file accessed, using fuser command. As shown above.

Code:
fuser -f "$file_dir" > tempfind.txt
pid=$(tr -dc "[:digit:]\n" < tempfind.txt)
  #7 (permalink)  
Old 10-01-2007
varungupta varungupta is offline
Registered User
  
 

Join Date: Feb 2007
Location: Pune, Dehradun (INDIA), Michigan(US)
Posts: 206
please check once again !!

Quote:
Originally Posted by vino View Post
Code:
fuser -f "$file_dir" > tempfind.txt
pid=$(tr -dc "[:digit:]\n" < tempfind.txt)
Thanks vino.
Don;t you think that to redirect the contents from the tempfind.txt file, unix creates a saperate process with unique Porcess id. And to truncate it creates another process with unique process id.
I think above command will club the process ids. (of all the processes used in above command) to one id, hence this clubbed id won;t be able get from ps table.

Its not working, means not giving the name of the user from the ps table according to the process id.

Please check it !!
Thanks in advance !!
Closed Thread

Bookmarks

« substring | vlad »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:57 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0