Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script problem

Status
Not open for further replies.

harpal

Technical User
Oct 3, 2001
115
GB
Hi,

I am writing a ftp script to transfer PX020625.001 files there are about 42 files altogther I have got the script to work ok heres the line for the ftp

today=PX020625*

echo "lcd $aw_leeds \nprompt\ncd /$pheonix_leeds \nmget $today\n" | ftp -v ho2kap01 >> $logfile

but what I need to achieve is to get the variable i have setup to automatically change day as this ftp takes place everyday and there is no archieving done on the server where I attending to pick up these files so tommorow I will have to pick up PX020626* i have tried the following varible but it has not worked does anyone have any ideas.

today=PX`%y%m%d`* but this does not work.

thanx in advance

Harpal
 
[tt]# today=PX`date +"%y%m%d"`*
# echo ${today}
PX020626*[/tt]

I must be confused. What exactly are you trying to do?

 
Works for me, perhaps you are omitting the space between 'date' and '+', or perhaps you are not using backticks. This should also work and might be clearer:

today=PX$(date +"%y%m%d")*

hth IBM Certified -- AIX 4.3 Obfuscation
 
well on a certain box I have to ftp 42 files of this format PXYYMMDD.001 .002 .003 and so on I have a working script if I set my variable as today=PX020625* the today varible will pick all file with that date stamp and any extension with the star wild card which is ok but this script needs to run out of cron everyday 365 days of the year the only prob is that the date in PXYYMMDD.001 changes every day so i need to set up variable that will change date as well so if i run script tommorow the files will be called PX020626.001 and so on. I have tried today=PX`date +%y%m%d`* and called the variable in the ftp bit of my script but this still does not work.

many thanks for all ur help
 
Why don't you cut and paste your complete script so we can see how it's formated. Don't re-type it....

today=PX$(date +"%y%m%d")*;echo $today
PX020626*


This should work just find.
Ed
 
cheers guy's your quite right that does work only 1 prob me being a plonk I I have set that above variable into my script and it works so for today the variable today=PX020627* but i need it to equal PX020626 as the file is always a day behind when we will pick it up as it is a sales file which has sales data for 020626 I had a look at the date stamp on the files from where my script will pick up the files and on that server the files are date stamped at PX020626.001 1 kb 001 File 27/06/2002 05:12 so i need the today variable to always be 1 day behind the unix date is the possible

thanx guy's

Harpal
 
Save the following as "yesterday.c", then do "cc -o yesterday yesterday.c". This is a one-function program, it simply returns yesterday's date in the format you wanted, no switches, no other functionality.
[tt]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#define SECSPERDAY 86400

int main()
{
time_t mangle;
struct tm* format;
char output[32];

mangle=time(&mangle);

mangle-=SECSPERDAY;

format=localtime(&mangle);

strftime(output,32,&quot;%y%m%d&quot;,format);

printf(&quot;%s\n&quot;, output);

}
[/tt]
 
chapter,

I do not have a c complier and where will the output to ur script go stdout of into a file.

cheers

Harpal
 
chapter

thanx mate works a treat jus a few question would it be possible for you to let me know how your script works as I have very limited sripting skills and also will there be any problems like in leap years and shorter months such as feb and months that finish wi 30th and 31st

cheers mate could not have done it wi out ur expertise

Harpal
 
None of those issues will crop up.

What the basic flow is:

Get the current date/time in unix format (number of seconds since the beginning of time (midnight 1/1/70 or thereabouts)).

Subtract a day's worth of seconds from that value, which makes that time value 1 day ago instead of *now*.

Convert that time value (still in unix number-of-seconds format) to a user-readable value, using the format you wanted (yymmdd).

The &quot;strftime&quot; function handles all of the ugliness of leap days, varying-length months, and so on, so that C program I just wrote up there will never have to change.
 
chapter,

cheers mate you were very helpful

Harpal
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top