Help me with daily monitoring script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help me with daily monitoring script
# 29  
Old 07-23-2013
Code:
find /usr/IBM/FileNet/BulkUploaderScript/$i/Log/SuccessLog \
   \( -newer range_start -a \! -newer range_end \) \
   | while read file
do
  
 lines=`wc -l "$file"`
# details=`ls -l "$file" | read w x y z d1 d2 d3 rest`--->commented ,in this intailzing is problem 
 details=`ls -l "$file"`
 echo $details
 echo "File $file has $lines lines and a date of $d1 $d2 $d3" 
 echo $file>>$LOGFILE
done

OUTPUT:
-rwxrwxrwx 1 ce_admin ce_admin 718 Jun 7 15:32 /usr/IBM/FileNet/BulkUploaderScript/LogsFolder/Log/SuccessLog/CSVSuccessLogHIPAACERTS7-6-2013 15-32-18.csv

File /usr/IBM/FileNet/BulkUploaderScript/LogsFolder/Log/SuccessLog/CSVSuccessLogHIPAACERTS7-6-2013 15-32-18.csv has 4 /usr/IBM/FileNet/BulkUploaderScript/LogsFolder/Log/SuccessLog/CSVSuccessLogHIPAACERTS7-6-2013 15-32-18.csv lines and a date of


I need only last modified date of the file not access time .
And i am getting number of lines with filename but i need only number.
Any alternative or any modifications
# 30  
Old 07-23-2013
Smilie Okay, I've spotted my first mistake. The output from ls -l "$file" has, of course, five colums to skip (permissions, links, owner, group & bytes) and what I suggested only has four dummy placeholders (w, x, y & z) Smilie

Lets try adding dummy placeholder v to that:-
Code:
find /usr/IBM/FileNet/BulkUploaderScript/$i/Log/SuccessLog \
   \( -newer range_start -a \! -newer range_end \) \
   | while read file
do
   lines=`wc -l "$file"`
   details=`ls -l "$file" | read v w x y z d1 d2 d3 rest`
   echo "File \"$file\" has \"$lines\" lines and a date of \"$d1\" \"$d2\" \"$d3\""
   echo $file>>$LOGFILE
done

I've added in a lot of escaped quotes \" so that the output clearly defines each variable to see if I've missed something else.

Can you have a go and post the output in code tags - it makes it easier to read.


Thanks Smilie, and apologies Smilie
Robin
# 31  
Old 07-25-2013
Still facing Issue that d1 ,d2,d3 not printing
Output::
Quote:
File "/usr/IBM/FileNet/BulkUploaderScript/LogsFolder/Log/SuccessLog/CSVSuccessLo gHIPAACERTS7-6-2013 15-32-18.csv" has"4/usr/IBM/FileNet/BulkUploaderScript/LogsFolder/Log/SuccessLog/CSVSuccessLogHIPAACERTS7-6-2013 15-32-18.csv" lines and a date of "" "" ""
# 32  
Old 07-25-2013
Maybe we shoudl drop the details= bit:-
Code:
find /usr/IBM/FileNet/BulkUploaderScript/$i/Log/SuccessLog \
   \( -newer range_start -a \! -newer range_end \) \
   | while read file
do
   lines=`wc -l "$file"`
   ls -l "$file" | read v w x y z d1 d2 d3 rest
   echo "File \"$file\" has \"$lines\" lines and a date of \"$d1\" \"$d2\" \"$d3\""
   echo $file>>$LOGFILE
done

A schoolboy error of mine Smilie that makes these values would only be set within the sub-shell running the ls -l | read......


Can you actually copy & paste all the code block in, as you output didn't quite tally.

Does that help?



Robin
# 33  
Old 07-26-2013
Code:
find /usr/IBM/FileNet/BulkUploaderScript/$i/Log/SuccessLog \
   \( -newer range_start -a \! -newer range_end \) \
   | while read file
do
  
  lines=`wc -l "$file"`
   ls -l "$file" | read v w x y z d1 d2 d3 rest
   echo "File \"$file\" has \"$lines\" lines and a date of \"$d1\" \"$d2\" \"$d3\""
   echo $file>>$LOGFILE
done

Quote:
File "/usr/IBM/FileNet/BulkUploaderScript/LogsFolder/Log/SuccessLog/CSVSuccessLogHIPAACERTS7-6-2013 15-32-18.csv" has " 4 /usr/IBM/FileNet/BulkUploaderScript/LogsFolder/Log/SuccessLog/CSVSuccessLogHIPAACERTS7-6-2013 15-32-18.csv" lines and a date of "" "" ""
Variable "lines" reading filename also with the number of lines in the file .Majorly problem is d1,d2,d3 is not showing any output .What is the solution we have now .

Thanks
Raghavendra
# 34  
Old 07-26-2013
Another variation to see where we're going:-
Code:
find /usr/IBM/FileNet/BulkUploaderScript/$i/Log/SuccessLog \
   \( -newer range_start -a \! -newer range_end \) \
   | while read file
do
  lines=`grep -c "" "$file"`
   ls -l "$file" | read v w x y z d1 d2 d3 rest
   echo "File \"$file\" has \"$lines\" lines and a date of \"$d1\" \"$d2\" \"$d3\""
   echo $file>>$LOGFILE
done

That should sort the counting. Testing here, the d1, d2 & d3 works fine for me:-
Code:
$ file=.profile
$ lines=`grep -c "" "$file"`
$ ls -l "$file" | read v w x y z d1 d2 d3 rest
$ echo "File \"$file\" has \"$lines\" lines and a date of \"$d1\" \"$d2\" \"$d3\""
File ".profile" has "12" lines and a date of "02" "May" "2012"
$

It would suggest that your code might have ls -1 | read .... instead of ls -l | read .... To clarify, you may have a number one where it needs a lower case L.


Can you have another go?


Robin
# 35  
Old 07-26-2013
ksh reads the last part of the pipe in the current shell:
Code:
ls -l "$file" | read v w x y z d1 d2 d3 rest

sh,bash need a work-around:
Code:
read v w x y z d1 d2 d3 rest << _EOT
`ls -l "$file"`
_EOT

Or
Code:
set -- `ls -l "$file"`
d1=$6; d2=$7; d3=$8

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Run script no more than twice daily WITHOUT cron

Can I run a script no more than twice a day without using cron? Maybe create a file when script is first run and check its date? (7 Replies)
Discussion started by: drew77
7 Replies

2. UNIX for Beginners Questions & Answers

/etc/cron.daily script is not being executed

Hi All I have created a file in /etc/cron.daily on redhat linux 7.3 version host called applicationscript cat applictaionscript #!/bin/bash /prod/data/routine.sh cat /prod/data/routine.sh #!/bin/bash #details regular=/prod/data/jboss/logs backup=/prod/data/logs #echo "Moving logs"... (3 Replies)
Discussion started by: anil529
3 Replies

3. Shell Programming and Scripting

Script to move file on a daily basis

Hi! Please I need help on the a script that would pick one file in a directory, change its name, them change its permissions, them move to a different directory, but has to be done on a daily basis, and the file that is being moved to its final destination has to have the following format:... (7 Replies)
Discussion started by: fretagi
7 Replies

4. Shell Programming and Scripting

Script for daily use

I have a clear case command for example. ct lsprivate -co this displays the list of checked out files. and i have many views where i work daily I need a script which can run daily at our specified time. setting each and every view i have and list the check outs i have in them. and consolidate... (10 Replies)
Discussion started by: Syed Imran
10 Replies

5. Shell Programming and Scripting

Daily health check script

Hi I am still learning how to write shell scripts, so I started to write a script like this: #!/bin/sh date echo outputOK () { echo $1 "" } outputOK () { echo $1 "" } for vol in `/usr/bin/grep -E 'hfs|vxfs|nfs|cifs' /etc/fstab | egrep -v '^#' | awk '{ print $3 }'` do if... (7 Replies)
Discussion started by: fretagi
7 Replies

6. Shell Programming and Scripting

Help with Daily DB growth script

Hello, I have a script SELECT TO_CHAR(creation_time, 'RRRR Month') "Month", SUM(bytes)/1024/1024 "Growth in MB" FROM sys.v_$datafile WHERE creation_time > SYSDATE-365 GROUP BY TO_CHAR(creation_time, 'RRRR Month') / It produces output similar to this Month ... (2 Replies)
Discussion started by: jnrpeardba
2 Replies

7. UNIX for Dummies Questions & Answers

Run a .sh script daily

Hi, I juat wondering how can you set it up so that .sh files will execute automatically once a day. from google I've got use crontab but when I type this into my session it say I am not allowed to use this programme. Any other ways to achieve what I'm looking for? thanks (1 Reply)
Discussion started by: blackieconnors
1 Replies

8. Shell Programming and Scripting

automating daily monitoring process

Hi there, I have to automate daily monitoring process and then the result of these process should be sent to a log file, then this log file should be mailed . ps -ef | grep aa In this atleast one process should run. If the process is running it should mention Success in the log file... (3 Replies)
Discussion started by: NehaKrish
3 Replies

9. Shell Programming and Scripting

Error in script to automate the daily monitoring process of UNIX server and it's proc

hi friends, I am trying to automate the daily monitoring process of UNIX server and it's processes. the script are below i executed the above script using ksh -x monitortest1.sh in root login . It shows error at some lines . 1. i logged in using root ,but it... (8 Replies)
Discussion started by: rdhaprakasam
8 Replies

10. UNIX for Dummies Questions & Answers

Need a script to do daily backups

So I have a set of directories and files that I need to backup from /directory1/ to /directory2/ each night. I have some UNIX/SSH knowledge but don't assume I know a whole lot b/c I would hate to screw something up. Here's the knowledge I have: I can access my server via SSH and can navigate to... (10 Replies)
Discussion started by: JPigford
10 Replies
Login or Register to Ask a Question