Sponsored Content
Top Forums UNIX for Advanced & Expert Users FTP "get" on files using date/time Post 25453 by Perderabo on Tuesday 30th of July 2002 02:26:31 PM
Old 07-30-2002
This script seems to work on my system. But as you say, the exact format of the ouput from "dir" can vary. So you may need to tweak it for your system. But anyway, it should get you real close. It relies on datecalc, another script that I wrote. You can find it by searching this site.
Code:
#! /usr/bin/ksh

#
#  Setup a few variables

SYSTEM=somehost
USER=joeblow
PASSWORD=*******
DIRECTORY=tmp

tmpfile=/tmp/ftpdir$$
thisyear=$(date +%Y)
today=$(datecalc -j $(date "+%Y %m %d"))
Jan=01 Feb=02 Mar=03 Apr=04 May=05 Jun=06 
Jul=07 Aug=08 Sep=09 Oct=10 Nov=11 Dec=12

#
#  Get a copy of the remote dir output in a local file
#  called $tmpfile and attach that file to stdin for reading

exec 5>&1 >$tmpfile 4>&1
ftp -nv  >&4 2>&4 |&
print -p open $SYSTEM
print -p user $USER $PASSWORD
print -p cd $DIRECTORY
print -p dir
print -p bye
wait
exec >&5 2>&1 < $tmpfile

#
#  Ignore lines until we get a line that starts with 150

IFS=""
looking=1
while ((looking)) ; do
        read line
        word1=${line%%${line##+([! ])}}
        [[ $word1 = 150 ]] && looking=0
done

#
# Loop getting lines that start with a "-"
# Then delete some leading fields

{
IFS="" 
while read line ; do
        char1=${line%%${line#?}}
        [[ $char1 != - ]] && continue
        line="${line##+([! ])}"
        line="${line##+([ ])}"
        line="${line##+([! ])}"
        line="${line##+([ ])}"
        line="${line##+([! ])}"
        line="${line##+([ ])}"
        line="${line##+([! ])}"
        line="${line##+([ ])}"
        line="${line##+([! ])}"
        line="${line##+([ ])}"
        echo "$line"
done ; } | {

#
# Second loop reads selected and shortened lines,
# Computes the date and may get the file

IFS=" "

exec 4>&1
ftp -nv  >&4 2>&4 |&
print -p open $SYSTEM
print -p user $USER $PASSWORD
print -p cd $DIRECTORY
while read month day swing name ; do
        eval month=\$$month
        if [[ $swing = *:* ]] ; then
                year=$thisyear
        else
                year=$swing
        fi
        julian=$(datecalc -j $year $month $day)
        if ((julian > (today-2))) ; then
                print -p get $name
        fi
done
print -p bye
wait
}
rm $tmpfile
exit 0

 

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

add seconds to: date"|"time"|"HHMMSS

Hey all, I have a shell that invokes a AWK. In this AWK i want invoke a function that receives 3 parameters: date: 20080831 time: 235901 duration: 00023 that function receive this 3 parameters and sum to this value two more seconds: 2008083123590100025 Remember that in case that... (3 Replies)
Discussion started by: anaconga
3 Replies

2. Shell Programming and Scripting

How to remove "New line characters" and "spaces" at a time

Dear friends, following is the output of a script from which I want to remove spaces and new-line characters. Example:- Line1 abcdefghijklmnopqrstuvwxyz Line2 mnopqrstuvwxyzabcdefghijkl Line3 opqrstuvwxyzabcdefdefg Here in above example, at every starting line there is a “tab” &... (4 Replies)
Discussion started by: anushree.a
4 Replies

3. HP-UX

FTP large files - Getting "Connection Refused"

Hello Friends, When i trying to transfer a huge amount of files via FTP to a HP-Unx server, I am getting an error "Connection Refused"...! How can i avoid this error. Regards, Prakash K:b: (4 Replies)
Discussion started by: bullz26
4 Replies

4. AIX

xx=`date +"%a %b %d"`;rsh xxx grep "^$XX" zzz ?

AIX 4.2 I am trying to do an rsh grep to search for date records inside server logs by doing this : xx=`date +"%a %b %d"` rsh xxx grep "^$XX" zzz gives : grep: 0652-033 Cannot open Jun. grep: 0652-033 Cannot open 11. But if I do : xx=`date +"%a %b %d"` grep "^$XX" zzz it works... (2 Replies)
Discussion started by: Browser_ice
2 Replies

5. Shell Programming and Scripting

"Join" or "Merge" more than 2 files into single output based on common key (column)

Hi All, I have working (Perl) code to combine 2 input files into a single output file using the join function that works to a point, but has the following limitations: 1. I am restrained to 2 input files only. 2. Only the "matched" fields are written out to the "matched" output file and... (1 Reply)
Discussion started by: Katabatic
1 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

awk "date" and "system" command

Hello experts! I need your help please I have a file.txt of which I want to extract 3rd and 4th columns with date with the form e.g.: 2016-11-25 03:14:50and pass them to "date" command, but also append the 9th column in a file as well. So I want to execute date -d '2016-11-25 03:14:50' ... (2 Replies)
Discussion started by: phaethon
2 Replies

8. Shell Programming and Scripting

Delete all log files older than 10 day and whose first string of the first line is "MSH" or "<?xml"

Dear Ladies & Gents, I have a requirement to delete all the log files in /var/log/test directory that are older than 10 days and their first line begin with "MSH" or "<?xml" or "FHS". I've put together the following BASH script, but it's erroring out: for filename in $(find /var/log/test... (2 Replies)
Discussion started by: Hiroshi
2 Replies

9. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies
XCALPR(1)						      General Commands Manual							 XCALPR(1)

NAME
xcalpr - print xcal calendar entries SYNTAX
xcalpr [ -c ][ -x ][ -f file ][ -d dir ][ -u user ][ date-spec ] DESCRIPTION
Xcalpr prints the contents of the xcal files. It is intended to be used in situations when you have no access to an X screen. It can also be used to generate entries for the standard UNIX calendar program. With no arguments, it prints any entries that exist for the next seven days. The program also reads the contents of the seven daily files and prints them at the appropriate point in the output stream. Each line in the output is preceded by the day of the week, the day of the month, the month and the year. Xcalpr can be given a date specification to select months and years. If the date spec consists of just a year number, then all the data for that year is printed. For example: xcalpr 1994 will print all the data for 1994. Several years can be specified. If you give the name of a month, then the data for that month in the current year will be printed. If the month is in the past, then the data for that month next year will be printed. For example, if xcalpr oct jan is typed in August, xcalpr will print October in the current year and January next year. You can select a particular year by adding the number after any months that you need printing: xcalpr oct nov 1994 will print October and November in 1994. There are a couple of special `month' names. The name rest will print the data for the rest of the month, starting tomorrow. The rest argument is not recognised if you give a year as a parameter. If tomorrow happens to be the first day of the next month, then all the data for next month will be printed. The name next prints all the data for next month. OPTIONS
The -c option causes xcalpr to output lines suitable for input to the standard UNIX calendar program. The -d switch is followed by a directory name and specifies an alterative location for your Calendar directory. Your home directory is prepended if the name doesn't start with a slash or a dot. The -f option is followed by a file name and xcalpr will write it's output to that file, rather than standard output. The -u option is followed by a user name and dumps their calendar files rather than yours. The -x option makes xcalev operate with Calendar files that are compatible with the xcalendar program. FILES
$HOME/Calendar/* xc<dd><Mon><Year> A data file is day, Month in three letter format and the year. xy<Year> A year directory. xw<Day> A data file for the weekly code, one per day. SEE ALSO
xcal(1), xcalev(1), xcal_cal(1) AUTHOR
Copyright 1993 by Peter Collinson, Hillside Systems All rights reserved. This product includes software developed by the University of California, Berkeley and its contributors. X Version 11 R5 October 1993 XCALPR(1)
All times are GMT -4. The time now is 03:44 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy