Visit Our UNIX and Linux User Community


Avoid file creation in a script...achive same result


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Avoid file creation in a script...achive same result
# 1  
Old 09-04-2009
MySQL Avoid file creation in a script...achive same result

Guys
following lines help me in getting numbers from PID column ,to be thrown into first column of a CSV file.


Code:
COLUMNS=2047 /usr/bin/ps -eo pid,ppid,uid,user,args | grep -v "PID" > /tmp/masterPID.txt
cat /tmp/masterPID.txt|while read line
do
PID=`echo $line|awk '{print $1}'`
echo "$PID"
done

Using following lines,i am able to print PPID column ,corrsponding to PID found above. [ Do not bother about "@@Host Processes.PID@@".My tool allows me to pass variables from column to column ]

Code:
PID="@@Host Processes.PID@@"
cat /tmp/masterPID.txt|while read line
do
temp=`echo $line|awk '{print $1}'`
if [ $temp = $PID ]
then
PPID=`echo $line|awk '{print $2}'`
echo "$PPID"
fi
done

My problem is ,even though i am able to get both columns in my CSV file,this code is doing a lot of I/O because of static file creation on box.I am myself against using a static file.

Is there a way i can achive the same without creating any file?

Regards
Abhi
# 2  
Old 09-04-2009
try:
Code:
PID="@@Host Processes.PID@@"
awk -v pid="$PID" '$1==pid {print $2}' /tmp/masterPID.txt

# 3  
Old 09-04-2009
MySQL

thanks jim,

let me re-phrase my problem..

i do not want "/tmp/masterPID.txt" file to be created in the first place...

i need to iterate following command's o/p to get all five columns...

"COLUMNS=2047 /usr/bin/ps -eo pid,ppid,uid,user,args"

Regards
Abhi
# 4  
Old 09-04-2009
I simplified a bit but does this not work for you?
Code:
COLUMNS=2047 ps -eo pid,ppid,uid,user,args | grep -v "PID" | while read line
do
 echo "$line"
done

# 5  
Old 09-08-2009
MySQL

Well ...thanks for the suggestion guys!!

I wrote like this:

PID:

Code:
COLUMNS=2047 /usr/bin/ps -eo pid,ppid,uid,user,args | grep -v "PID" |while read line
do
PID=`echo $line|awk '{print $1}'`
echo "$PID"
done

PPID:

Code:
PID="@@Host Processes.PID@@"
COLUMNS=2047 /usr/bin/ps -eo pid,ppid,uid,user,args|grep -v "PID" |while read line
do
temp=`echo $line|awk '{print $1}'`
if [ $temp = $PID ]
then
PPID=`echo $line|awk '{print $2}'`
echo "$PPID"
fi
done

I am getting desired columns but there is a small issue here.Some processes shut down or hibernate for some time.

I am losing PPID,UID,USER,ARGS columns for some PIDs.

This is how it looks :


Code:
Host Name	PID	PPID	UID	USER	COMMAND

<hostname>	323830				
<hostname>	307638				
<hostname>	360788				
<hostname>	106618	1	0	root	/usr/lib/errdemon
<hostname>	110744	123026	0	root	/usr/sbin/dpid2
<hostname>	114688	123026	0	root	/usr/sbin/syslogd
<hostname>	118976	123026	0	root	sendmail:


Reason probably is i am passing whole command again as an input to 'while' loop.

Earlier when i was putting it in a file,it was a snapshot on which iteration was happening.

Now i have two questions:

1.How can above issue be handled?

2.Is there any way looping can be avoided ? [ I am personally of the opinion that loop is must if i have to catch whole row ].

Regards
Abhi

Previous Thread | Next Thread
Test Your Knowledge in Computers #801
Difficulty: Medium
The CSS z-index property specifies the stack order of an element.
True or False?

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Need UNIX script to check checksum and dummy file creation.

Hi Folks, I need a UNIX script which will copy files(Table wise) from source directory to destination directory (Under table directory) and also creates 2 additional files after getting copied to destination directory with extension .pdy and .ldy , . pdy file will be zero byte file should get... (4 Replies)
Discussion started by: Nicks1412
4 Replies

2. Shell Programming and Scripting

Script to print file name and its creation date

Hello , I am looking for a script to print file name and its last updated time. FILE CREATION-TIME FILE-NAME 24/10/2017 12:34 TDR-IU-8-2017.10.24.07:40:00-2017.10.24.07:45:00 when we run l command it print the directory and the files with details like permission,... (1 Reply)
Discussion started by: sadique.manzar
1 Replies

3. Shell Programming and Scripting

CSV File Creation Within Shell Script

Hi All, I am trying to create a CSV file within a shell script test.ksh and the code snippet is something like below: #!/usr/bin/ksh # Set required variables. . $HOME/.prof # Output file path Group1=/tmp/G1.csv Group2=/tmp/G2.csv Group3=/tmp/G3.csv $ORACLE_HOME/bin/sqlplus -s... (2 Replies)
Discussion started by: swasid
2 Replies

4. Shell Programming and Scripting

List creation - Grep a line in a file with a script name

Hi, I have a list file which has script names in them. Some scripts take lists as parameters which inturn have script names. This is basically for sequencing the job run. Eg: List1: test1.ksh test2.ksh test2.lst test3.ksh test3.lst test4.ksh test2.lst: test21.ksh test23.ksh... (7 Replies)
Discussion started by: member2014
7 Replies

5. Shell Programming and Scripting

File system creation script on AIX 6.1 using while loop

#!/bin/sh echo "VG: " read VG echo "LP: " read LP echo "SAP: " read SAP echo "NUM: " read NUM echo "SID: " read SID while ]; read VG LP SAP NUM SID ; do mklv -y $SAP$NUM -t jfs2 -e x $VG $LP; crfs -v jfs2 -d /dev/$SAP$NUM -m /oracle/$SID/$SAP$NUM ... (14 Replies)
Discussion started by: arorap
14 Replies

6. Shell Programming and Scripting

Script to write result to a file

Hello, How can I run this script every 1 hour and save its result to result.txt ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}' Regards Shaan (5 Replies)
Discussion started by: Shaan_Shaan
5 Replies

7. Shell Programming and Scripting

Script not spooling in result file

Hi everyone and nice to meet you :) I'm having some issues with a script I'm writing. It's probably most chaotic, I'm no ksh guru, but the idea is to extract an ID with that query, spool it into a file, and read that file making the ID a variable. This has to be done for every row extracted by... (10 Replies)
Discussion started by: Arkadia
10 Replies

8. Shell Programming and Scripting

shell script result to file

Since I'm not an expert in shell scripting, I have question on sending script result to file. I have script like this... if condition=0: then echo "service is not running" | mail -s "Server Status" uname@companyname fi sleep 10 if configtion=1: then echo "service is not running" | mail -s... (3 Replies)
Discussion started by: s_linux
3 Replies

9. Shell Programming and Scripting

Creation of script,if the data file have more than one entry!!!

1.Daily there will be 14 files in the data directory 2.someday's the 14 files receive more than once r twice with different time stamps....we need to chk the count of the file and if the count of the file is two.we need to combine the both the files. 3. if any duplicate data is there just... (1 Reply)
Discussion started by: bobprabhu
1 Replies

10. Shell Programming and Scripting

Creation and Transfer of TAR file from one machine to another Using UNIX script

Hi, I want to create unix script such that it should run on machine A, it should run TAR commands on machine B and copy that TAR to machine C. Is it possible? Thanks Rahul (2 Replies)
Discussion started by: rahuljadhav
2 Replies

Featured Tech Videos