11Jun
You need to do something on a daily with a file in a directory named yyyy-mm-dd.txt (year-month-day.txt).
That's easy enough:
#!/bin/ksh
# just get the current date
today="`date +%Y-%m-%d`"
filename="${today}.txt"
echo $filename
Oops, you need the file from yesterday. Not so simple any more as the unix date command just sets or prints the date.
Let's do some of the usual date math (month ends, leap years, etc.).
#!/bin/ksh
# default is one to travel back in time to yesterday
daystogoback="1"
# to be a little dynamic, we can use an argument to go back n days.
if [ $# -eq "1" ]; then
daystogoback="$1"
fi
# get the current year month and day
nowy=`date +%Y`
nowm=`date +%m`
nowd=`date +%d`
# get rid of the month's possible leading zero
nowm=`echo $nowm*1|bc`
# if today's day is greater than the number of days to go back
# we really can just take the shortcut and subtract the days to go back
# because we will stay in the current month and nothing fancy is needed
if test $nowd -gt $daystogoback
then
nowd=`echo $nowd-$daystogoback|bc`
else
# if we are in January, we have to go to the previous year
# and set the month to December
# else we can just subtract the month
if test $nowm -eq "1"
then
nowy=`echo $nowy-1|bc`
nowm="12"
else
nowm=`echo $nowm-1|bc`
fi
# now we can calculate the day, but first we have to see
# how many days in the month...
# we default to 31 and do nothing more for the months with 31 days
# we have to check for February and then for a leap year (28/29)
# the rest of the months will have 30 days
newd="31"
case "$nowm" in
"1") ;;
"3") ;;
"5") ;;
"7") ;;
"8") ;;
"10") ;;
"12") ;;
"2") if test "0" -eq "`echo $nowy%4|bc`"
then
newd="29"
else
newd="28"
fi ;;
*) newd="30" ;;
esac
# subtract the current day from the days to go back
# and then from the total days in the month
nowd="`echo $daystogoback-$nowd|bc`"
nowd="`echo $newd-$nowd|bc`"
fi
# now we just do some formatting for the month and day
if test $nowm -lt "10"
then
nowm="0$nowm";
fi
if test $nowd -lt "10"
then
nowd="0$nowd";
fi
# our new date
filedate="$nowy-$nowm-$nowd"
# and the file we need to access...
filename="${filedate}.txt"
echo $filename
Always fun playing with dates.
References:
KSH script BASICS
Wikipedia: Korn shell
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5
26Mar
It has been a while since i have had to work with Informix / 4GL. I have already forgotten tha simple commands to view the current running SQL query with an executing 4GL script. So this is more of a note to myself, but if it helps you, I'll be overjoyed.
First find the correct process:
> ps -ef | grep glgo
root 7618 7368 63 22:58:19 pts/ta 0:21 fglgo the_4gl_name_here
Then get the correct session using the pid from the previous result:
> onstat -g ses | grep 7618
1644203 root ta 7618 myserver 1 200704 187952 off
Now get the current executing sql of the session id above:
> onstat -g sql 1644203
If you would like the display to be automatically refreshed, just add a 'r' switch:
> onstat -gr sql 1644203
I hope I will remember to come and look for this next time I need it in a few months time.
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5
29Dec
After searching for ever, I finally managed to compile a sed script to convert CSV formatted files to Informix unload format (bar-delimited) files.
Hope I help someone with this.
#************************************************#
# csv2unl.sh #
# #
# written by Riaan Lehmkuhl #
# Dec 29, 2006 #
# #
# sed to convert csv to bar-delimited records. #
#************************************************#
# usage: ./csv2unl.sh < infile > outfile #
#************************************************#
/./!d
s/\([^\]\)|/\1\\\\|/g
s/\`/\'/g
s/^ *\(.*[^ ]\) *$/|\1|/;
s/" *, */"|/g;
: loop
s/| *\([^",|][^,|]*\) *, */|\1|/g;
t loop
s/ *|/|/g;
s/| */|/g;
s/^|\(.*\)|$/\1/;
s/"//g
s/$/|/g
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5