write a UNIX script for the following

can someone help me to write a single UNIX script for the following two scripts :

script1 file1.d<today's date in the format yyyymmdd>
script2 <one date back in the format:mmmddyy>

rvsBhanuAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

woolmilkporcCommented:
Hi,

I think I don't really understand your requirement.

What I can say

"today's date in the format yyyymmdd" is date +"%Y%m%d"
for concatenation with a given string: use e.g. filename="file1.d"$(date +"%Y%m%d") ; echo $filename

"one date back in the format:mmmddyy" (I assume "mmm" means "month with a leading zero") is date -d "1 day ago" +"0%m%d%y"
concatenate like above:  filename="file1.d"$(date -d "1 day ago" +"0%m%d%y") ; echo $filename

Note - for the second command above to work you need GNU date. What is your operating system?

wmp


0
omarfaridCommented:
For one day back, try to play with your TZ env variable:

TZ=GMT-24 ; export TZ
0
omarfaridCommented:
that was an example for GMT time zone
0
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

rvsBhanuAuthor Commented:
the operating system is UNIX.
mmm in the second script means first three alphabets for the month..is it possble to get it that way..?

basically I want to combine these two script into a single script .
So I am looking for the script that can be used at one go..instead of two separate ones.
0
woolmilkporcCommented:
You will get the first three characters of the month's name with date +%b"

But I'm still far from understanding what you're trying to achieve.

What is the script supposed to do? What should be its output? What the input, if any?


0
ozoCommented:
what system do you need this for, and what version of the date command does it ues?
if you have the gnu version of date, you can do
date -d yesterday +"%b%d%y"
some other systems may allow a 24 hour timezone offset, some may not.
(and even there you have have to be careful within an hour of midnight the day after a daylight saving switch)
0
rvsBhanuAuthor Commented:
I basically have these two scripts which I want to make as one.As of now the output of the first one is used as the input for the second one.

So basically I need a script wherein with just one command I am able to execute both of them.Hope that helps.

Wud require help in writing such a script.
0
rvsBhanuAuthor Commented:
as an exaample the commands that are run as of now are :

script1 file1.d20090712
script2 jul1209

I want to write a single script for both of them,wherein the output of the first is given as input to the second and I get the final o/p.
0
woolmilkporcCommented:
I fear you will have to post both of your scripts.
Without knowing their content I can't get the clue of what you're trying to achieve.

0
rvsBhanuAuthor Commented:
I want to combine the two scripts into one,ie.by running a single script both of these should be executed.

#!/bin/csh
filename="file1.d"$(date +"%Y%m%d") ; echo $filename
script1 file1name
echo "script1 completed"
date1=date -d yesterday +"%b%d%y"
script date1
echo "script2 completed"
#

Please let me know if the above is correct ?
0
woolmilkporcCommented:
OK,
I still don't understand what the scripts are supposed to do,
but here some corrections:

#!/bin/csh
filename="file1.d"$(date +"%Y%m%d")
script1 $filename
echo "script1 completed"
date1=$(date -d yesterday +"%b%d%y")
script2 $date1
echo "script2 completed"
#
exit

I removed the echo from the second line, I put it in in my post above only for illustration purposes.
The date strings we composed form commandline parameters for your scripts 'script1' and 'script2'.
Is this what you intended?

wmp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rvsBhanuAuthor Commented:
yes,actually the file1 created has date as the primary diffrentiator.

So I want the script1 to work taking today's date as an parameter concatenated with a filename.
And script2 to run with yesterday's date as a parameter in the format mmmddyy,where mmm is the first 3 letters of the name of the month.

So is the script correct for this purpose ?
0
woolmilkporcCommented:
Yes it is!
0
rvsBhanuAuthor Commented:
I tried to run the below script,but it gives me an error : Variable syntax

#!/bin/csh
filename="file1.d"$(date +"%Y%m%d")
./script1 $filename
echo "script1 completed"
date1=$(date -d yesterday +"%b%d%y")
./script2 $date1
echo "script2 completed"
#

can someone please check and let me know where it is to be corrected ?
0
rvsBhanuAuthor Commented:
when I  give date command I get the following o/p :

Tue Jul 14 09:54:38 EDT 2009

So is the above script correct for this version of date ?However,it gives me variable syntax error.

How can I get this to be working ?
0
woolmilkporcCommented:
Oh, sorry,
just saw that you're using a shell which is incompatible with the syntax used.
Simply change the very first line of the script to contain
#!/bin/ksh
and it will work!
wmp
0
rvsBhanuAuthor Commented:
It still gives me an error.finalscript3 is the name given to the script .

It gives me the following error :
-----------------------------------------------------------------
./finalscript3[2]: date+%Y%m%d:  not found
Enter only one valid file name
Syntax: ./script1 <filename>
script1 completed
./finalscript3[5]: date-d:  not found
enter date suffix for the filename in the format mmmyy..
script2 completed
-------------------------------------------------------------------------------
Can you pls chk and let me know what is causing the error ?
0
woolmilkporcCommented:
This should not happen if you ran the script as you posted it in 24849295.
Could you please post the script exactly as you try to run it? It just seems as if there were some spaces or quotes missing.
0
rvsBhanuAuthor Commented:
here is the script that I am running :

#!/bin/ksh
filename="file1.d"$(date+"%Y%m%d")
./script1 $filename
echo "script1 completed"
ydate=$(date-d yesterday+"%b%d%y")
./script2 $ydate
echo "script2 completed"
#
-------------------------------------------------------
Pls chk and let me know what is causing the error ?
0
woolmilkporcCommented:
filename="file1.d"$(date +"%Y%m%d")
ydate=$(date -d yesterday +"%b%d%y")
There must be spaces between
date and +  
yesterday and +
date and -d


0
rvsBhanuAuthor Commented:
Script1 runs successfully now.

But I still get an error when I try to run the script2.
Below is the error that I am getting :
---------------------------------------------------------------------------------
./finalscript3[5]: date-d:  not found
enter date suffix for the filename in the format mmmyy..
script2 completed
----------------------------------------------------------------
0
woolmilkporcCommented:
Well,
I told you that you need a space between date and -d
0
rvsBhanuAuthor Commented:
well my script now looks like this,but still gives the error:

---------------------------------------------------------------------
#!/bin/ksh
filename="file1.d"$(date +"%Y%m%d")
./script1 $filename
echo "script1 completed"
ydate=$(date -d yesterday +"%b%d%y")
./script2 $ydate
echo "script2 completed"
#

----------------------------------------------------------------------
error:
date: illegal option -- d
usage:  date [-u] mmddHHMM[[cc]yy][.SS]
        date [-u] [+format]
        date -a [-]sss[.fff]
enter date suffix for the filename in the format mmmyy..

Please suggest ?
0
rvsBhanuAuthor Commented:
how can I determine whether my OS supports the GNU date command ?if not,wat can be given in its place to resolve the above error ?
0
woolmilkporcCommented:
You could install GNU date if it's not there. GNU date is available for almost any UNIX platform. Now I need to know exactly which platform you're on. Please post the output of
uname -a
0
rvsBhanuAuthor Commented:
% uname -a
SunOS dvc7600 5.9 Generic_118558-38 sun4u sparc SUNW,Netra-T12
0
rvsBhanuAuthor Commented:
any resolution for this ?

well my script now looks like this,but still gives the error:

---------------------------------------------------------------------
#!/bin/ksh
filename="file1.d"$(date +"%Y%m%d")
./script1 $filename
echo "script1 completed"
ydate=$(date -d yesterday +"%b%d%y")
./script2 $ydate
echo "script2 completed"
#

----------------------------------------------------------------------
error:
date: illegal option -- d
usage:  date [-u] mmddHHMM[[cc]yy][.SS]
        date [-u] [+format]
        date -a [-]sss[.fff]
enter date suffix for the filename in the format mmmyy..

0
woolmilkporcCommented:
GNU date is part of GNU coreutls.

Find the version for your OS here:

http://www.sunfreeware.com/programlistsparc9.html#coreutils

Download- and installation instructions are here:

http://www.sunfreeware.com/download.html

wmp



0
rvsBhanuAuthor Commented:
what is the other alternative in case I cannot get this installed as I do not have perms on the box.?
does the error show that GNU is not installed..?
is there any other alternative script that can be written ?If yes,what can that be ?
0
rvsBhanuAuthor Commented:
can someone pls help with the alternative script ?
0
omarfaridCommented:
On my system I have TZ=GMT+4 , so when I run date command e.g. I get

Wed Jul 15 06:39:22 GMT 2009

When I change TZ to

TZ=GMT+28

and run

date

I get

Tue Jul 14 06:40:49 GMT 2009

which is one day back

can you replace the line below

ydate=$(date -d yesterday +"%b%d%y")

with something like

TZ=GMT-24
ydate=$(date +"%b%d%y")

Please see your actual time zone with

echo $TZ

0
rvsBhanuAuthor Commented:
Below is the o/p that I get when I give date and TZ command :

% date
Wed Jul 15 09:41:59 EDT 2009
% echo $TZ
TZ: Undefined variable

Pls look into this and suggest something ?
0
omarfaridCommented:
can you set it as

TZ=EDT+24 ; export TZ

and then run

date

and see results (This is what I could see from your date output that the Timezone for you is EDT)
0
rvsBhanuAuthor Commented:
% TZ=EDT+24;export TZ
TZ=EDT+24: Command not found
export: Command not found

Pls suggest ?
0
omarfaridCommented:
what is your shell? run

env

OR

set

and see vaiable like SHELL or shell
0
TintinCommented:
rvsBhanu is using csh, in which  case, either do

setenv TZ EDT+24
date

or

ksh
export TZ=EDT+24
date
0
rvsBhanuAuthor Commented:
would TZ work for all days like for DST also ?
else is there some other alternative to the below line of script :
ydate=$(date -d yesterday +"%b%d%y")
 
0
omarfaridCommented:
I think this is gnu date which looks like you don't have it installed on your system.
0
omarfaridCommented:
I think this is gnu date which looks like you don't have it installed on your system.
0
omarfaridCommented:
I think this is gnu date which looks like you don't have it installed on your system.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.