Sponsored Content
Top Forums Shell Programming and Scripting Flag Programs that have coding problems Post 302973831 by dellanicholson on Sunday 22nd of May 2016 07:39:40 PM
Old 05-22-2016
Flag Programs that have coding problems

I create a shell script program (AIX OS) that flags any logs that certain keywords such as memsize, sasfoundation, and real time. My program isn't working maybe because my syntax logistic isn't correct.

Here are examples of the logs:
file1.log.02897 file2.log.02896 filez.log.02899 file4.log.02898 file5.log.028999 file6.log.02898 filex.log.028999 filem.log.028999
file11.log.028999 filexx.log.028999 file56.log.028999 filexz.log.028999 fileq.log.028999

first three attachments are examples of data in each the log files:

last attachment progflag.csv is an example of how the result needs to be displayed in the file.

Here is my code:
Code:
#!/bin/bash

#tar current logs and move the tar package to /tmp/log . Untar a logs

sudo cd /home/user/myfiles ; tar cf - */*/*.log.* | ( cd /tmp/log ; tar xf - )

#change all files under  log directory to write and execute
chmod 775 files =/tmp/log/*.*

#set target threshold to 3600 sec.   (1hour)
echo threshold = 3600

#read in multiple .log files from directory /tmp/log

for file in /tmp/log/*.log.*; do
    while read -r LINE; do
        echo "$LINE"

# search for keywords line by line
  flag_line=$(echo $LINE | awk '{print $NF}')

# if MEMSIZE has a value, extract value and then Output column name MEMSIZE and values to progflag.csv
  if echo $flag_line "MEMSIZE" | cut -d: -f2 then 
  echo MEMSIZE=$flag_line 

# extract numeric value from row titled REAL TIME

 if echo $flag_line "REAL TIME:" | cut -d: -f3 then 
  echo SEC=$flag_line
  
# if sec is greater than threshold then output column name SECOND and values to progflag.csv
  IF $sec  > $thresold then
   echo SECOND=sec

# if path SASFoundation exist than extract SASFoundation and add SASFoundation to alias SASEXE.  Output column name SASEXE and 
    value to  progflag.csv

  if echo $flag_line '/SASFoundation' grep SASFoundation
   echo SASEXE=$flag_line
   
   #output each title of filename with extracted data to progflag.csv
  
  Echo filename=$LINE
    Echo $MEMSIZE $SECOND $SASEXE $LINE
 done < "$file"  >> progflag.csv

#send the attachment via email
 if progflag.csv then
(cat ./progflag.csv)|mailx -s "subject text" -a "Programs flagged" receiver@domain.com

#after process is completed, remove all files from directory tmp/log
 sudo rm -rf $files $progflag.csv

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

the flag -c in sh command

I need your help please. In a production system, i've seen many running process as follow: sh -c ./pathname/shellname what exactly the flag option -c is used for? ive tried to look at the man page, but it doesnt say much. ill appreciate yor help. Thanks (4 Replies)
Discussion started by: alexcol
4 Replies

2. Shell Programming and Scripting

Problems with find's -newer Flag

I am writing a script that looks in a reports directory, copies a specified script to a working folder, copies some data files into the working folder, runs the report, zips the new files, then uploads them. Right now to determine what files to zip (as I don't know how many report files there... (6 Replies)
Discussion started by: droppedonjapan
6 Replies

3. AIX

du flag -x

Hi, I would like to know if there's any option to use with the du command so that I can list only the files/directories on the current filesystem... I usually use du -gs *But I'd like to see only the directories in the filesystem I am on, and not the mount point directory of other fss... ... (6 Replies)
Discussion started by: Casey
6 Replies

4. UNIX for Dummies Questions & Answers

Are programs like sys_open( ) ,sys_read( ) et al examples of system level programs ?

Are the programs written on schedulers ,thread library , process management, memory management, et al called systems programs ? How are they different from the programs that implement functions like open() , printf() , scanf() , read() .. they have a prefix sys_open, sys_close, sys_read etc , right... (1 Reply)
Discussion started by: vishwamitra
1 Replies

5. Shell Programming and Scripting

Add the flag

#!/bin/bash while : do ./abc.sh PB sleep 60 ./abc.sh RA sleep 60 ./abc.sh GS sleep 68400 done Instead of making the script sleep for sometime, it doesn't work all the time as time may shift over a period. How to make a script wake up every 30 seconds and check the current time, if... (2 Replies)
Discussion started by: sandy1028
2 Replies

6. AIX

Flag issue

Hi all, We dont have access to aix source code and i have a doubt. The flag SC_NO_RESERVE, is it got to do anything with the failover? If the flag is set the paths are going to failed state. If flag is not set everything comes up fine after failover. Thanks in advance for helping ... (2 Replies)
Discussion started by: gnakul
2 Replies

7. UNIX for Dummies Questions & Answers

'h' flag in du

Hey, all! Why is the "human readable" flag changing the behavior of du? And while I'm at it, can you make du only look at files, not directories. I often find myself wanting to find the largest file(s) in a dir or vol. Using 'find' itself, it seems you have to at least be able to guess the size of... (2 Replies)
Discussion started by: sudon't
2 Replies

8. UNIX for Dummies Questions & Answers

Get the id with specify flag

.... means multi line ddd,bug fgdrg dfdfsdfdfsd fsdfdfdfd fdfdsfdsfsd ....... flag2 ...... aaa,bug sfsfsfsfs dfdfsdfdfsd fsdfdfdfd fdfdsfdsfsd ...... flag1 ...... ddd,bug fgdrg dfdfsdfdfsd (9 Replies)
Discussion started by: yanglei_fage
9 Replies

9. UNIX for Dummies Questions & Answers

Difference between inbuilt suid programs and user defined root suid programs under bash shell?

Hey guys, Suppose i run passwd via bash shell. It is a suid program, which temporarily runs as root(owner) and modifies the user entries. However, when i write a C file and give 4755 permission and root ownership to the 'a.out' file , it doesn't run as root in bash shell. I verified this by... (2 Replies)
Discussion started by: syncmaster
2 Replies

10. Shell Programming and Scripting

sed print flag

I have an input file that looks something like this: .... key1: ABC .... key2: DEF .... key1: GGG .... key2: HHH .... The row of dots represents any number of lines that don't contain the strings "key1:" or "key2:" The strings key1: and key2: will always appear alternately as in the... (8 Replies)
Discussion started by: pmennen
8 Replies
All times are GMT -4. The time now is 01:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy