FTP random files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting FTP random files
# 1  
Old 11-21-2007
FTP random files

Hello everyone,

What I'm trying to do is figure out how to ftp a set of random files each day about 50 or so maybe more or less.

I have a folder on my server that gets about 1000 or so new files each day, each with today's date in the file name. We just want to take a sample each day for quality checks.

eg. testnumberssomethingelse20071121morenumbers

What I need to do is grab 50 random files for today's date and upload them via ftp. I have all the code for ftp and what not, I just don't know how to pick out 50 or so files out of 1000+ and direct them to my ftp process.

Here is my current script without randomization, which I've gather mostly from here.

Code:
#! /bin/ksh
stty -echo
#print -n Enter Password-
#read PASS
print
stty echo
exec 4>&1

HOST=iphere
USER=test123
DESTDIR=/
SOURCEDIR=/something1/something2
PASS=test123

cd $SOURCEDIR

ftp -nv >&4 2>&4 |&
print -p open $HOST
print -p user $USER $PASS
print -p binary
#print -p cd $DESTDIR

ls | while read filename ; do
        [[ -f $filename ]] && print -p put $filename
done
print -p close
print -p bye
wait
exit 0

Any help would be greatly appreciated.

Thank you
# 2  
Old 11-21-2007
Use the rand() command

1) List the filenames to a file
2) Use rand(no. of filenames in the file)
3) Use the result of the rand() as the position of the filename list in the file.
4) Get the filename to ftp
# 3  
Old 11-21-2007
Here is a cool trick that I'm borrowing from cfajohnson... First put a random number in front of each file name:

ls | awk 'BEGIN {srand()} {printf "%.0f %s \n",rand()*99999, $0; }'

then sort it. This will put the lines in a random order. Then just pick the first few lines:

ls | awk 'BEGIN {srand()} {printf "%.0f %s \n",rand()*99999, $0; }' |sort -n | head -2 | awk '{print $2}'
# 4  
Old 11-21-2007
Perderabo/cfajohnson,

This works great!

Thank you.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to see the status of all the ftp put & get files logs and curent ftp transfer status ?

How to see the status of all the ftp put & get files logs and curent ftp transfer status if any active ftp running in the background ? (2 Replies)
Discussion started by: i4ismail
2 Replies

2. Shell Programming and Scripting

Need to generate a file with random data. /dev/[u]random doesn't exist.

Need to use dd to generate a large file from a sample file of random data. This is because I don't have /dev/urandom. I create a named pipe then: dd if=mynamed.fifo do=myfile.fifo bs=1024 count=1024 but when I cat a file to the fifo that's 1024 random bytes: cat randomfile.txt >... (7 Replies)
Discussion started by: Devyn
7 Replies

3. Solaris

list any random first 5 files with 'ls'

I just need to see any number of random files to see the owner, group and permissions information since all the files in the directory have the same permissions and ownership information. Is it possible just to list any 5 files without going thru the series of commands such as "ls -ltu | head -5"... (8 Replies)
Discussion started by: yoonkim
8 Replies

4. Shell Programming and Scripting

copying random Jpg files to different folder

Hi, I have 200 pictures in a folder and I would like move 10 random pictures every week to given folder automatically. I have this server on 1and1.com. So I tried the following using Bash script for manual copy and paste for testing #!/bin/bash mapfile -t -n 3 files < <(find... (13 Replies)
Discussion started by: raamkum
13 Replies

5. Ubuntu

expect script for random password and random commands

Hi I am new to expect. Please if any one can help on my issue its really appreciable. here is my issue: I want expect script for random passwords and random commands generation. please can anyone help me? Many Thanks in advance (0 Replies)
Discussion started by: vanid
0 Replies

6. Shell Programming and Scripting

Auto Ftp pseudo random file

I have a script that generates a file which is my own incarnation of a date using the 'date' function (we'll call this script a). I would like that script to invoke my other script (script b) which contains my ftp info. Since I have yet to figure out a good way to use regular ftp (yes i can only... (6 Replies)
Discussion started by: DC Slick
6 Replies

7. Shell Programming and Scripting

shell script to auto process ten random files and generate logs

Hello member's I'm learning to script in the ksh environment on a Solaris Box. I have 10 files in a directory that I need to pass, as input to a batch job one by one. lets say, the files are named as follows: abcd.txt ; efgh.bat ; wxyz.temp etc. (random filenames with varied extensions ).... (1 Reply)
Discussion started by: novice82
1 Replies

8. Filesystems, Disks and Memory

Not able to FTP the files to a FTP server

Hi , We are facing a weird problem in our project. we need to send some xml & audio files to a remote FTP server from a Linux box, we are doing this in Perl script using Net::FTP->. Issue here is.. when FTPed the files using Perl scripts, only empty files ( 0 byte) are getting created on the... (2 Replies)
Discussion started by: kishorepotta
2 Replies

9. Shell Programming and Scripting

Random files do not FTP in the shell script

The following script is used to loop through files in the /tmp directory and transfer those files onto another server. However, some of the files do not transfer. It is very random when the transferring is done (i.e. one of the files won't transfer then next time, that one will transfer and... (1 Reply)
Discussion started by: RLatham20
1 Replies

10. Shell Programming and Scripting

Random parameters passing in FTP script

Hi I have a question. In the FTP script if we are passing all the required value like Hostname, username, password, Action(put or get), Filename, & mode(ascii or binary) through parameters then we have to pass these in the exact orders in which they are taken like if we defined Username=$2... (2 Replies)
Discussion started by: sourabhshakya
2 Replies
Login or Register to Ask a Question