Sponsored Content
Top Forums Shell Programming and Scripting moving log file into Archive directory Post 302453611 by mohullah on Wednesday 15th of September 2010 11:02:38 PM
Old 09-16-2010
moving log file into Archive directory

Hi All,

I'm trying to write a script which will do following :

- For any old log under trace directory, if found move it to Archive
- Check for a process “process-A” if it is running abort from the script
- Else start it up (start_process-A.sh this case)
- If it fails to start the process, exit with the appropriate exit code
- All of the above steps will be logged in the log file under trace
Code:
#!/bin/ksh
SERVICE='process-A'
JOB=`basename $0`
OWNPID=$$
LOGFILE=$HOME/trace/$JOB$OWNPID.log
Archive=$HOME/trace/Archive
 
archive()
{
if [ -f $HOME/trace/ start_process-A.sh.*.log ]; then
  mv $HOME/trace/ start_process-A.sh.*.log $Archive
else
  echo "No file to archive" | tee -a ${LOGFILE}
  exit 1;
fi
}

>>>> The above function moves all the files to the Archive directory as I used wildcard (*) but I want to keep the latest file (which will be generated upon completion of this script) in the trace directory and rest in the Archive directory. I have done lots of search in the google and just cannot find it. Any help will be appreciated.
Code:
# Checking process-A .. if not found - equals to 1, start it
ps -ef | grep $SERVICE | grep -v grep
if [ $? -eq 1 ]
then
  echo "`date` : $SERVICE is down, starting up ..." | tee -a ${LOGFILE}
  $HOME/ start_process-A.sh | tee -a ${LOGFILE}
else
  echo "`date` : $SERVICE is up ..aborting from the script" | tee -a ${LOGFILE}
fi
#Moving old log file into Archive directory
archive

>> Is there a was to check the start_process-A.sh script is failed or hung? if so how do I redirect it to the log file?

Last edited by Franklin52; 09-16-2010 at 02:57 AM.. Reason: Please use code tags, thank you!
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Create Year directory, date subdirectory and archive the file

Hi, After checking all the UNIX threads, I am able to come up with a solution so far. I am working on a shell script where it moves the files to a certain directory. The conditions to check are 1) Check if the file exists in the current directory. 2) Check if the destination directory... (2 Replies)
Discussion started by: madhunk
2 Replies

2. Shell Programming and Scripting

Moving file to directory based on condition.

Can any one help me to correct following script. I have 2 directories DropZone and ProcessZone. File pattern is *VEHDESCSUM*. Finding the 'no of files' in DropZone directory using ls *VEHDESCSUM* |wc -l If DropZone has more than one file or 0 files then exit 1 If DropZone has one file then... (2 Replies)
Discussion started by: ramanagh
2 Replies

3. Shell Programming and Scripting

moving file to directory in script

hi i am reading files from directory,if the files matches certain condition i need to move that file to another directory i am using if then mv $file1 > $UNIQDIR fi but i am gettin error , please help thanks Satya (4 Replies)
Discussion started by: Satyak
4 Replies

4. Shell Programming and Scripting

ftp a file after checking the versions not greater then 8 in archive directory

Hi , I want to write a FTP Script which checks the No of Vesions of the files in Archive Dir and if count >= 8 Delete the oldest file from the Archive Dir and if the count is <= 8 Move the file to the Archive Dir with a CurrentDate concatenation and FTP the file to the FTP directory and send... (1 Reply)
Discussion started by: kailash.jadhav
1 Replies

5. Shell Programming and Scripting

Moving files listed in a data file to a new directory using Perl

Hi, I have a data file that lists a number of files. I want to move the files named in that one to another directory. Here's what I have: #!/usr/bin/perl -w open(FILE, "<collision.txt"); my @lines=<FILE>; foreach my $lines (@lines) { system("mv $lines collisions/."); } close(FILE); ... (2 Replies)
Discussion started by: renthead720
2 Replies

6. Shell Programming and Scripting

Shell Script for moving 3 days old file to Archive Folder

Hi Experts, I have a "Source" folder which may contain some files. I need a shell script which should move all files which are older than 3 days to "Archive" folder. Thanks in Advance... (4 Replies)
Discussion started by: phani333
4 Replies

7. Shell Programming and Scripting

Grepping file names, comparing them to a directory of files, and moving them into a new directory

got it figured out :) (1 Reply)
Discussion started by: sHockz
1 Replies

8. UNIX for Dummies Questions & Answers

Reading the dates from a file & moving the files from a directory

Hi All, I am coding for a requirement where I need to read a file & get the values of SUB_DATE. Once the dates are found, i need to move the files based on these dates from one directory to another. ie, this is how it will be in the file, SUB_DATE = 20120608,20120607,20120606,20120606... (5 Replies)
Discussion started by: dsfreddie
5 Replies

9. Homework & Coursework Questions

Archive and purge the log file

Hi Unix Experts, I am new in this filed. I have assignment to Archive and purge the log file using shell scripts I tried I could not get the result please help me this. Ex: test.log requirement : using shell script I need to archive the log file and nil and the content of (test.log)... (1 Reply)
Discussion started by: johney1981
1 Replies

10. Shell Programming and Scripting

Moving Files one directory to another directory shell script

Hi, Could you please assist how to move the gz files which are older than the 90 days from one folder to another folder ,before that it need to check the file system named "nfs" if size is less than 90 or not. If size is above 90 then it shouldn't perform file move and exit the script throwing... (4 Replies)
Discussion started by: venkat918
4 Replies
FSTRACE_CLEAR(8)					       AFS Command Reference						  FSTRACE_CLEAR(8)

NAME
fstrace_clear - Clears the trace log SYNOPSIS
fstrace clear [-set <set name>+] [-log <log name>+] [-help] fstrace c [-s <set name>+] [-l <log name>+] [-h] DESCRIPTION
The fstrace clear command erases the contents of the trace log from kernel memory, but leaves kernel memory allocated for the log. OPTIONS
-set <set name>+ Names the event set for which to clear the associated trace log. The only acceptable value is "cm" (for which the associated trace log is "cmfx"). Provide either this argument or the -log argument, or omit both to clear the "cmfx" log by default. -log <log name>+ Names the trace log to clear. The only acceptable value is "cmfx". Provide either this argument or the -set argument, or omit both to clear the "cmfx" log by default. -help Prints the online help for this command. All other valid options are ignored. EXAMPLES
The following command clears the "cmfx" trace log on the local machine: # fstrace clear PRIVILEGE REQUIRED
The issuer must be logged in as the local superuser "root". SEE ALSO
fstrace(8), fstrace_lslog(8), fstrace_lsset(8) COPYRIGHT
IBM Corporation 2000. <http://www.ibm.com/> All Rights Reserved. This documentation is covered by the IBM Public License Version 1.0. It was converted from HTML to POD by software written by Chas Williams and Russ Allbery, based on work by Alf Wachsmann and Elizabeth Cassell. OpenAFS 2012-03-26 FSTRACE_CLEAR(8)
All times are GMT -4. The time now is 07:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy