Sponsored Content
Top Forums Shell Programming and Scripting For loop or while loop from a text file Post 303013301 by nms on Monday 19th of February 2018 10:42:32 AM
Old 02-19-2018
For loop or while loop from a text file

Hi all,

i developed a script to measure the uptime of a process in a Solaris 10/11 environments.
All is well, but i came across a situation where there are multiple processes of the same name. Basically i have the following result file:

Code:
beVWARS 13357 19592122
beVWARS 14329 19591910
beVWARS 6371 20436149
beVWARS 6368 20436149
beVWARS 6374 20436149
beVWARS 13361 19592118
beVWARS 13988 19591989
beVWARS 6367 20436149
beVWARS 6365 20436149
beVWARS 6355 20436149
beVWARS 6363 20436149
beVWARS 14055 19591982
beVWARS 13267 19592147
beVWARS 13562 19592097
beVWARS 6361 20436149
beVWARS 14228 19591944

Where first column is the process name, followed by it's pid and the uptime in seconds.

i am trying to find a way to get the uptime vs. an if condition (by a loop?) where if the uptime is less then say 3600 seconds it outputs the process and it's pid on the same line.

Bascially i tried:

Code:
while read line; do
if [[ $line -lt $CRITICAL_SIZE ]]; then
echo -n `grep $line $CRONOUTFILE | awk '{print$2,$3}'`
fi
done <<< "$TIME"

Where $TIME contains only the 3rd column, i.e. the uptime, but it's not working as it should.
$CRONOUTFILE is the output file as shown above.
What i am trying to achieve is to output only the process and pid in a similar output:

Critical - the following processes $PROCESS are less then $CRITICAL_SIZE - $PID:$TIME, $PID:$TIME...,$PID:$TIME

Where the $PROCESS can be easily set an argument in the script.

I am totally confused in using the for loops or the while loop. May you kindly give me some hints?

Rgds,

Matthew
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Get data from two text file in one loop

Hi all I have two file that contain different data.I want to get each file data line by line in one loop.i try with cat but cat works ok against one file File a 23 34 45 File b abc xyz cgh now i want like this in a loop.Below is just example.i am doing some thing smiler.can any... (3 Replies)
Discussion started by: aliahsan81
3 Replies

2. Shell Programming and Scripting

Storing the values in text file using while loop in shell script

Hi Frdz while read line do name=`echo $line | cut -d' ' -f 1 ` password=`echo $line | cut -d`-` -f 2` name > logfile.txt password > logfile.txt done < list.txt When it is run, am getting last values in list.txt file only,it is not storing lall the list entry values. How can i... (5 Replies)
Discussion started by: KiranKumarKarre
5 Replies

3. Shell Programming and Scripting

while loop to add text to the end of a file

Hi all, I've got 2 files. File 1 has a list say a b c d e f File 2 got start= What I want is to create File 3 which look like this start=a,b,c,d,e,f So is it possible to loop throught File1 to echo it into File3 in one line? (3 Replies)
Discussion started by: stinkefisch
3 Replies

4. Fedora

How to read a text file and assign the values in the same to a variable in loop

Hi, I have a text file with multiple lines, each having data in the below format <DOB>,<ADDRESS> I have to write a script which reads each line in the text file in loop, assign the values to these variables and do some further processing in it. Using the following code prints the... (1 Reply)
Discussion started by: manishab00
1 Replies

5. UNIX for Advanced & Expert Users

How to read a text file and assign the values in the same to a variable in loop

Hi, I have a text file with multiple lines, each having data in the below format <DOB>,<ADDRESS> I have to write a script which reads each line in the text file in loop, assign the values to these variables and do some further processing in it. Using the following code prints the values... (12 Replies)
Discussion started by: manishab00
12 Replies

6. Shell Programming and Scripting

matching user input to a text file loop?

until do read -p "Invalid cars. Try againa" cars1 done Ok i have the above code, im getting users input and if it doesnt match in the file the user has to try again untill its correct But when i run this it gives me an error saying ./Cars.bash: line 43: (2 Replies)
Discussion started by: gangsta
2 Replies

7. Shell Programming and Scripting

Reset while loop to loop same file multiple times

Hi, I want to read file multiple times. Right now i am using while loop but that is not working. ex. While read line do while read line2 do echo stmt1 #processing some data based on data., done < file2.txt done < file1.txt # This will have 10... (4 Replies)
Discussion started by: tmalik79
4 Replies

8. Shell Programming and Scripting

How to loop a text file to remove the old files?

Hi , I'm using Ksh 88 version. I've a text file which contains the directory names DIR1 DIR2 ---- DIR10 I've to remove the data which has more that 30 days from the above directories . The data has to be removed from the following path cd /home/etc/DIR1/hist cd /home/etc/DIR2/hist... (2 Replies)
Discussion started by: smile689
2 Replies

9. Shell Programming and Scripting

Loop through the dir and Rename zip files and their underlying text file.

I have files in the ABC_YYYYMMDD.zip format under a directory. Each zip file contains A text file in the ABC_YYYYMMDD.txt format. I am trying to create a script that will Rename the zip files and their underlying text file replacing the datepart in them with . For eg: in the case of... (1 Reply)
Discussion started by: bash987
1 Replies

10. Shell Programming and Scripting

Problem with while loop reading every line of a text file

Hello, I'm using RHEL 5.1 with bash. How to handle "read" inside while loop reading every line? Please see below: # cat /tmp/passwd_sample CARRJ12:qVSn4ja4mFA72,..:20021:125:JULIAN CARR:/home/everyone:/bin/bash HERCOT01:NK/3j2ZB4ZC7Q:20022:125:TOM HERCOCK:/home/everyone:/bin/bash... (4 Replies)
Discussion started by: reddyr
4 Replies
UPTIMED(8)						      System Manager's Manual							UPTIMED(8)

NAME
uptimed - daemon to record uptime records SYNOPSIS
uptimed [ -?bv ] [ -e <email> ] [ -i <interval> ] [ -m <count> ] DESCRIPTION
This manual page documents the uptimed program. uptimed is a daemon that records statistics about a machine's uptime. Use the uprecords(1) program to get uptime record statistics. OPTIONS
These command-line options override settings in the configuration file /etc/uptimed.conf -? Show usage -b Create bootid and exit. This option is ignored on BSD systems, because the BSD kernel keeps a static boot time variable in memory so Uptimed does not need to cache this value. -p <file> Write PID to pidfile <file> -e <email> Send mail to <email> at milestones/records -i <interval> Use <interval> seconds for loop -m <count> Log a maximum of <count> entries -t <timespec> Set the minimum uptime to be considered a record -v Show version information SEE ALSO
uprecords(1) AUTHOR
Rob Kaper <cap@capsi.com>. This manual page was written by Alan Ford <alan@whirlnet.co.uk>, for the Debian GNU/Linux system (but may be used by others). It was last modified for uptimed version 0.3.7. May 28, 2004 UPTIMED(8)
All times are GMT -4. The time now is 01:06 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy