Mabuhay

Hello world! This is it. I've always wanted to blog. I don't want no fame but just to let myself heard. No! Just to express myself. So, I don't really care if someone believes in what I'm going to write here nor if ever someone gets interested reading it. My blogs may be a novel-like, a one-liner, it doesn't matter. Still, I'm willing to listen to your views, as long as it justifies mine... Well, enjoy your stay, and I hope you'll learn something new because I just did and sharing it with you.. Welcome!
Showing posts with label cron. Show all posts
Showing posts with label cron. Show all posts

Thursday, January 29, 2009

Scripting 101: Purging Files

Ei-lo! 'Zup? I'm beginning to enjoy this I guess: scripting. Unexpected, I got a ping from a former colleague, asking from a noobs [read: me] regarding scripting. Without blinking, I accepted the challenge. I was asked to check on the script she made for purging files. After checking on the requirements, given, and asking for advise from a scripting guru [Morsgang Freeman], below are the revised forms. Btw, the first one I made really sucks [I hope these won't :(]. As of writing, these are not tested, not 'til tomorrow when she receives the email/script.

1. First is to create a file, say SUBDIR.txt with the ff. contents:


MERGE/REJECTS/ARCHIVE

MERGE/REJECTS/ARCHIVERAW

MERGE/FILTERED/ARCHIVE

MERGE/FILTERED/ARCHIVERAW

INSERT/REJECTS/INSERTED

INSERT/FILTERED/INSERTED

FTP/FTP_ARCHIVE


2. I made two variations of the script:
a. Version 1

#!/bin/bash

export LOGDIR=/ramsys_data/bmcps/ramsys/
export DIRLIST="ALTL AMA5 CAMA FREE NRTL SEGR UTSS"

for XXX in DIRLIST
do
cd $LOGDIR
if [ "$PWD" = "$LOGDIR" ]
then
for PURDIR in `cat SUBDIR.txt`
do
# A log file can be added here [good practice] to list the files to be deleted...
find $XXX/$PURDIR -type f -name "*" -mtime +5 -exec rm {} \;
done
else
echo "Check $USER\'s permissions; cannot change to $CURDIR."
# You can add a mailer here for notification...
exit 1
fi
done


b. Version 2

#!/bin/bash

LOGDIR=/ramsys_data/bmcps/ramsys/
DIRLIST="ALTL AMA5 CAMA FREE NRTL SEGR UTSS"

cd $LOGDIR || {
echo "Check the permissions; can't change to $CURDIR."
# You can add a mailer here for notification...
exit 1
}

for XXX in DIRLIST
do
for PURDIR in `cat SUBDIR.txt`
do
# A log file can be added here [good practice] to list the files to be deleted...
find $XXX/$PURDIR -type f -name "*" -mtime +5 -exec rm {} \;
done
done


If this will be run in cron, e.g. everyday at 0100H, we can make it as:

0 1 * * * ( scriptname_here.sh > /if_wanted/can/store/to/logfile 2>&1 ) &

Or throw it to /dev/null. Whatever suits you.

Monday, September 29, 2008

Unicenter Autosys: job scheduling tool

I was sad and excited, may be li'l bit happy, when I started with my new work. Sad for am going to miss colleagues, the Neptune project in whole, except the SAP team - no love lost, among others. Excited for a new challenge looms; I thought.

I was useless/worthless in my team for the whole month - FICC IT PTF, whatever that means; while the team comprises: Indian, Chinese, locals [Singaporean], and us - Pinoy. Lucky for us, one of the shift leads or station managers is a Pinoy; I call him The Director - I find the job bit boring. It may be because I still don't have the access on other applications but, it could be the job is - as my shift lead puts it - for kindergarten. Sorry, just quoting. It makes me miss my SYSSUPPORT access. But, of course, this doesn't mean that I'm gonna stop writing about UNIX. Nada! It's a continuous learning. Next target: Solaris and RHEL. We got books here, as well as, CBTs.

On the side note, I came to learn a new application. It's the Unicenter Autosys - a job scheduling tool. Just like the Control-M, the one that we use before. It's just like a cron job, with conditions that can be set in order for that job to run. As for my job, in our team, tickets are assigned via "tasks". You are assigned tasks to be done on certain time [with or without SLA]. So, everyone has got something to do. You can't run, you can't hide!

As for the Autosys, we use it to check on jobs if they run successfully or otherwise. As mentioned, jobs should meet certain conditions before it will be executed. Such conditions ranges from time to dependencies to other jobs. I'll post here next time some results from my tasks. As for the meantime, please read on Unicenter Autosys.

*************************************************************
The "as for now" is over. I "stole" some results from the tasks assigned to me today. You may have read about it but here is the example:

user101@server202> aj IRS_server203_EOD-EUR

Job Name Last Start Last End ST Run Pri/Xit
__________________ _____________ _____________ __ _______ ___

IRS_server203_EOD-EUR 09/30/2008 21:00 09/30/2008 21:11 SU 24773663/1
user101@server202> aj IRS_server203_EOD-EUR -q

/* ----------------- IRS_server203_EOD-EUR ----------------- */

insert_job: IRS_server203_EOD-EUR job_type: c
command: $$XXX/Scripts/Autosys/IRS_server203_EOD-EUR.sh
machine: server203
#owner: XXX
permission: gx,mx
date_conditions: 1
days_of_week: mo,tu,we,th,fr
start_times: "21:00"
description: "Rerun=0;663;Chat : XXX ; DL-xxx-yyy , DL-zzz-aaa"
std_err_file: $$XXX/Scripts/Autosys/Logs/IRS_server203_EOD-EUR.err
min_run_alarm: 1
max_run_alarm: 10
alarm_if_fail: 1
timezone: US/Eastern
user101@server202> aj IRS_server203_EOD-EUR -r -1

Job Name Last Start Last End ST Run Pri/Xit
__________________ _____________ _____________ __ _______ ___

IRS_server203_EOD-EUR 09/29/2008 21:00 09/29/2008 21:13 SU 24728737/1
user101@server202>


You might wonder about the "aj" command, and you may not find it anywhere. Before chaos reigns in our midst, it's just an alias for "autorep -J".

Here, another example - a running job:

user101@server202> aj FI_
FCTxx_DownStream_BOX
Job Name Last Start Last End ST Run Pri/Xit
_______________ _____________ ____________ __ _______ ___

FI_FCTxx_DownStream_BOX 09/30/2008 21:29 ----- RU 24767669/1
FI_
FCTxx_Settlement 09/30/2008 21:29 ----- RU 24767669/1
FI_
FCTxx_JetBase 09/30/2008 21:30 09/30/2008 21:31 SU 24767669/1
FI_
FCTxx_JetBase_SFtp 09/11/2008 21:38 09/11/2008 21:38 OI 24115468/1
FI_
FCTxx_Socrates 09/30/2008 21:29 09/30/2008 21:30 SU 24767669/1
FI_
FCTxx_Socrates_SFtp 09/30/2008 21:30 09/30/2008 21:31 SU 24767669/1
FI_
FCTxx_MRC 09/30/2008 21:29 09/30/2008 21:30 SU 24767669/1
FI_
FCTxx_MRC_SFtp 09/30/2008 21:30 09/30/2008 21:31 SU 24767669/1
FI_
FCTxx_CPVar_SFtp 09/30/2008 21:30 09/30/2008 21:31 SU 24767669/1

user101@server202> job_depends -c -J FI_
FCTxx_Settlement
______________________________________________________
Start Dependent
Job Name Status Date Cond? Cond? Jobs?
-------- ------ --------------- ----- ---------
FI_
FCTxx_Settlement RUNNING No No No
______________________________________________________

user101@server202>
job_depends -d -J FI_
FCTxx_Settlement
Job Dependency Report

Job Name Date Cond? Atomic Start Conditions
______________________ _______________ ________________

FI_
FCTxx_Settlement ------- -------
user101@server202>


World Clock