Visit Our UNIX and Linux User Community


Request to modify script to list multiple parameters for V_fieldid variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Request to modify script to list multiple parameters for V_fieldid variable
# 1  
Old 03-30-2008
Request to modify script to list multiple parameters for V_fieldid variable

I am posting a script below which essentially excutes the following functions in the described order.

1) From a source directory pools together three files generated by system logs for each user session, tar's these files and archives them as a log set in a destination directory and these removes the three files which were zipped and archived from the source directory.

2) The zipped and archived logset will be tagged as sudosh.actual date the files were created (mm/dd/yyyy) format .hostname .tar

3) The script is designed to clear a backlog of files created in source directory of each box.

4) If there were no user log files on a particular day then a zero tar logset is created with a tag .nologs.sudosh. date (mm/dd/yyyy) .hostname.tar and archived in destination directory.

Note : Th script works fine when there are no log files and just files generated by one user session which gives only one "v_fileid" parameter to the script.

However if there are multiple user sessions generating multiple log files on a a particular day it creates multiple parameters for teh V-fileid variable which the script is unable to process and denotes an error that files could not be opened for that particular day .

can someone assist me by showing how I can update the "v_fileid" variable to accept a list or multiple parameters in addition to zero and one parameter for a particular day and process the rest of the script to accomplish the tasks noted above.

I believe there may be a small syntax modification that can be done to the existing script to make it accept and work in the scenario where there are more several files created in the source directory because of multiple user sessions generating a list of parameters for the v_fileid variable in the script noted below.

Request urgent assistance in making this script work when zero, one or multiple parameters exist for a given day. Thank you.

#! /usr/bin/ksh
--cd /var/adm/sammy/sourcedir
srcdir=/home/sam/srcdircat
trgdir=/home/sammy/trgdir

cd $srcdir

h=$(hostname)
--ts=`date '+%m%d%Y'`

v_mon=Jan
v_day=01
v_year=`date '+%Y'`

x=0
while [ $x -le 90 ]
do

echo x is $x

case $v_mon in
Jan) v_file_mon=01;;
Feb) v_file_mon=02;;
Mar) v_file_mon=03;;
Apr) v_file_mon=04;;
May) v_file_mon=05;;
Jun) v_file_mon=06;;
Jul) v_file_mon=07;;
Aug) v_file_mon=08;;
Sep) v_file_mon=09;;
Oct) v_file_mon=10;;
Nov) v_file_mon=11;;
Dec) v_file_mon=12;;
*) exit 1;;
esac


ts=$v_file_mon$v_day$v_year

echo ts is $ts

v_fileid=`ls -l |awk '$6 == "'$v_mon'" && $7 == "'$v_day'" { print $9 }'|awk -F"-" '{ print $4 }'|sort -u`

echo v_fileid is $v_fileid

if [ "$v_fileid" ]; then

echo "files exist, proceed to processing"

v_files=`ls -l|awk '{ print $9 }'|grep $v_fileid`
--v_file_month=`ls -l|grep $i|awk '{ print $6 }'|sort -u`
--v_file_day=`ls -l|grep $i|awk '{ print $7 }'|sort -u`
echo files are $v_files
tslog=sudosh.$h.$ts
tar -cvf $tslog.tar $v_files
tar_status=`echo $?`

if [ $tar_status -eq 0 ]; then
echo "tar file created successfully"
mv $srcdir/$tslog.tar $trgdir/$tslog.tar
rm $v_files
else
echo "tar file creation failed"
fi



else
echo "no file present"
logfile=nologs.sudosh.$h.$ts.txt
tslog=nologs.sudosh.$h.$ts
echo "no file today $ts" >>$logfile
tar -cvf $tslog.tar $logfile
mv $srcdir/$tslog.tar $trgdir/$tslog.tar
rm $logfile

fi

if [ "$v_mon" == "Jan" ] && [ "$v_day" == "31" ]; then
v_mon=Feb
v_day=01
elif [ "$v_mon" == "Feb" ] && [ "$v_day" == "29" ]; then
v_mon=Mar
v_day=01
else
v_day=`expr $v_day + 1`
if [ $v_day -le 9 ]; then
v_day=0`echo $v_day`
fi
fi

x=`expr $x + 1`
echo x is $x
done

Previous Thread | Next Thread
Test Your Knowledge in Computers #237
Difficulty: Easy
Paul Baran was the first to build a theoretical model for communication using packet switching.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Modify line with dynamic variable in awk

Hi, I'm guessing this is probably relatively straight forward to do in awk, but I just can't get my head round it! I have a log file of the following format: 3:03:35 (lmgrd) TIMESTAMP 10/14/2011 3:20:41 (MLM) IN: "MATLAB" user1@host1.private.dns.zone 3:21:05 (MLM) IN: "MATLAB"... (2 Replies)
Discussion started by: chrissycc
2 Replies

2. Shell Programming and Scripting

Script to List, Modify, replace filename for an upload?

Hello, here is my problem: I have ma program in a first directory dir1: ls path1/rep1/ file1.f90 file1.f90~ file1.o file2.f90 .... etc... I have modified folder in an other directory: ls path2/rep2/ file1_modified.f90 file2_modified.f90 .... etc... All files from first... (8 Replies)
Discussion started by: shadok
8 Replies

3. Programming

Modify php script to allow multiple countdowns within one page.

Hi, I have the following php countdown script that counts down to a date and time. Please see the below example: <SCRIPT language="JavaScript" SRC="countdown.php?timezone=US/Pacific&countto=2011-06-25 00:00:00&do=t&data=Sorry, This Offer Has Expired."></SCRIPT> And countdown.php: ... (1 Reply)
Discussion started by: rocket_dog
1 Replies

4. Shell Programming and Scripting

awk modify multiple columns with pipes

Hello, I have a CSV-like dataset where some of the columns contain HTML snippets which I need to convert to XHTML. For any given snippet, I have a functioning config for the text processor 'tidy' such that tidy -config tidy.cfg example.html does the job I need done. I would like to process... (10 Replies)
Discussion started by: bstamper
10 Replies

5. Programming

Number of days in month from certain parameters, c programming request.

Hi, I have an issue in date processing, the issue is I have a month as an int ( 1 - 12 ), the weekday as int ( 0 - 6 , 0 = Sunday), and the week day in month as int ( 0 - 5, 5 = last ex: first sunday, last monday, third tuesday ... ), now from those three parameters is there a possible way to... (2 Replies)
Discussion started by: modn3
2 Replies

6. Shell Programming and Scripting

Modify sources.list from script

i'm looking for a way to enable and disable repositories from a script. i started with a sed command like this: sed '/*'"$REPO"'/,/'"$STOP"'/ s/^*//' /etc/apt/sources.list but this enables both the normal and the source repos. for example: # deb http://www.lamaresh.net/apt lenny main #... (7 Replies)
Discussion started by: Leppie
7 Replies

7. UNIX for Advanced & Expert Users

How to modify BASEDIR with request script?

Here is request script: #!/bin/sh echo "Current install root path is " CONFIRM="n" while do BASEDIR="" while true do echo please input install root path then press : read BASEDIR if then echo... (6 Replies)
Discussion started by: kingpmp
6 Replies

8. Shell Programming and Scripting

how to modify the value of the variable

Hi I have a variable which holds full path to the file, for example z=/bb/data3/f4222pdb.dta.new I need to remove the extension .new so it would look like z=/bb/data3/f4222pdb.dta Is there a command to do this? This variable is used in the "for" loop later. I am in ksh. Thanks a lot -A (4 Replies)
Discussion started by: aoussenko
4 Replies

9. Shell Programming and Scripting

How to modify the variable

I have a directory name stored in a variable. Does anyone have a piece of code which checks if this stored directory name ends up with the "/" and if it is missing adds it to the same variable. for example I might have A=/bb/data or A=/bb/data/ which needs to be A=/bb/data/ for sure thanks... (5 Replies)
Discussion started by: aoussenko
5 Replies

10. UNIX for Dummies Questions & Answers

Modify semaphores parameters on Linux

Hello, I need to modify the semaphores parameters on a Linux server Debian 2.2.R3. How can I do it? Thks. (6 Replies)
Discussion started by: annececile
6 Replies

Featured Tech Videos