korn shell script guidance


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting korn shell script guidance
# 1  
Old 09-14-2011
korn shell script guidance

Please look over my short comings during this line if questions.

I have multiple lines in a file that look like,

Code:
phycook 618722      1  76 12:15:13 pts/122 70:24 /4js/runtime2.02.10/lib/fglrun-bin initmenu.42r
 phycook 593484      1  65 12:15:18 pts/122 69:22 /4js/runtime2.02.10/lib/fglrun-bin initmenu.42r

I was thinking I could put this in a for loop like so.

Code:
for 1 2 3 4 in $(cat outfile)
do 
echo $4
done

Since there are spaces between each value in each line that would set the value in the first column for line 1 to $1 and would set the value in the 2nd column for line 1 to #2 and so on. Then I could check $4 for a certain value and if true then the next step would be to kill the process which would be in $2.

Please don't laugh. I somehow think I remember doing something like this but can't find the freaking code in another script.

So if I didn't do a good job of explaining above I basically want to take the value in 4th column and if it's above a certain number run a kill against the PID which is the value in column #2.

Thank you for your time.
# 2  
Old 09-14-2011
for the below code, it will check whether the 4th column is greater than 50. If it is, then it will issue a kill command for the processid (2nd column)

i included echo in the below code, just exeucte it and check whether it gives the correct output (as u expect). If yes, then remove the echo part.

Code:
 
awk '{if($4 > 50) print "echo kill -9 " $2}' inputfile| sh

# 3  
Old 09-14-2011
WOW itkamaraj,

Maybe that's not big to everyone but it's hugh to me. Thank you very much. I dream of the day I have the "knowledge" power. I appreciate your quick response.

It did work as expected but if you have time would you consider adjusting to check for the 7th column (70:24) and if it is above 05:00 then kill the processid? Meaning if the value in column 4 and the value in column 7 are both true then kill the processid.
# 4  
Old 09-14-2011
Code:
 
awk '{if($4 > 50 && substr($7,1,index($7,":")-1) > 5) print "echo kill -9 " $2}' inputfile | sh

---------- Post updated at 08:12 AM ---------- Previous update was at 08:00 AM ----------

Added one mroe condition for checking the minutes also.

Code:
 
awk '{if($4 > 50 && substr($7,1,index($7,":")-1) >= 5 && substr($7,index($7,":")+1,length($7)) > 0 ) print "echo kill -9 " $2}' test

This User Gave Thanks to itkamaraj For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

pass null value to sql script from korn shell script

There are 4 parameters that I have to pass from korn shell to sql script. 1) I have to check if $1 , $2 , $3 and $4 are null values or not . How can I do that ? 2) Once its determined that these values are null (in the sense they are empty) how can I pass null values to sql script... (11 Replies)
Discussion started by: megha2525
11 Replies

2. Shell Programming and Scripting

Guidance needed for a typical shell script with sql query

Hi , I have a txt file with contents like: 1234 2345 3456 7891 I need to write a script which takes input file as txt file..run a sql query for that number and place the output of query in another file.. select * from bus_event where acct_nbr='1234'( from input txt file) the query... (20 Replies)
Discussion started by: Rajesh Putnala
20 Replies

3. Shell Programming and Scripting

Help me to write as korn shell script

Hi.. This is step to telnet from linux to my window telnet server and run a program called CLISMS.exe. As your information, the program will be sent out a sms to my mobile number. The step as below:- telnet 123.123.123.123 Trying 123.123.123.123... Connected to 123.123.123.123. Escape... (1 Reply)
Discussion started by: bh_hensem
1 Replies

4. AIX

weird korn shell script

here is the one of the scripts: script1.kshfunction haha { print "calling haha" exit } script2.ksh. script1.ksh haha | tee -a /dev/null print "i am script 2" after launching the script2, the result: --------------------------------------------- calling haha i am script 2 ... (6 Replies)
Discussion started by: getter
6 Replies

5. Homework & Coursework Questions

Korn Shell Script

1. The problem statement, all variables and given/known data: Write a korn shell script with an alfanumeric string as argument. The script lists the file's names in the current directory that contain the given string as substring and that can be read and written. 2. Relevant commands, code,... (3 Replies)
Discussion started by: burm
3 Replies

6. Shell Programming and Scripting

Korn Shell Script

I have to solve some exercises in Korn Shell, but i'm having some problems. For example: Write a korn shell script with an alfanumeric string as argument. The script lists the file's names in the current directory that contain the given string as substring and that can be read and written. I... (3 Replies)
Discussion started by: burm
3 Replies

7. Solaris

Problems with korn shell script

Hey Guys, I'm looking for some advice about a korn shell script I've written. I've spent hours googling for an answer hopefully someone here can help me out. Basically the part of the script I'm having problems with is when I need to SFTP a file from one server to another. The line looks... (6 Replies)
Discussion started by: hilather
6 Replies

8. AIX

Help with Korn Shell script

I have this Korn shell script that runs via a cron entry. It runs in a loop "watching" a specific file system for files with a certain name. The file system that it is watching is an upload file system for an FTP server. When files that are the correct name come in, it takes the extension of the... (1 Reply)
Discussion started by: heprox
1 Replies

9. UNIX Desktop Questions & Answers

korn shell script

hi all i am writing the korn shell script. i have a SQL script which gives me the folowing output DSA.WLG.20050713211544.20051025.20050713211544 28991 1130198400 DSA.WLG.20050713211544.20051025.20050713211544 25881 1130198400 DSA.WLG.20050711210100.20051025.20050711210100 25881 ... (3 Replies)
Discussion started by: pavan_test
3 Replies

10. UNIX for Dummies Questions & Answers

korn shell script

hello., i have 2 files.. 1 file is in this folder /home/test/ssk/DSA.WLG.20050713211544.20050710.20050713211544 (this part) other file is in this folder /home/kk/dev/DSA.WLG.20050711210100.20050710.20050711210100 ... (1 Reply)
Discussion started by: pavan_test
1 Replies
Login or Register to Ask a Question