Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

send random file (sendmail)

Original Message
Name: lndsey
Date: February 26, 2008 at 05:44:55 Pacific
Subject: send random file (sendmail)
OS: unix
CPU/Ram: none
Model/Manufacturer: none
Comment:
Hi,
I am trying to send a random files of mail in the mail folder. The mail folder has thousand of mails and I would like to randomly take files in there and send it. I have the following sendmail command, but don't know how I can send any random file from mail folder.
sendmail -Ad -i -f root@localhost you@smtp.net < FILENAME

Report Offensive Message For Removal


Response Number 1
Name: nails
Date: February 27, 2008 at 09:50:33 Pacific
Subject: send random file (sendmail)
Reply: (edit)
This script will choose a random file from a directory. (I'll leave the actual sendmail command to you). I use the ksh/bash RANDOM variable to generate a random number. Below, generating $s1 & $s2 to seed RANDOM might look confusing, but I do that to increase the "randomness":

#!/bin/ksh

# set your own directory
# cd /mydir

# send the directory contents to a file one per line
myfile="/tmp/myfile"
ls -1 > $myfile

# how many files are there
counter=$(wc -l < ${myfile})

# seed the RANDOM number generator
s1=$(/usr/bin/ps -elfy)
s2=$(/usr/bin/cat -s /etc/shadow)
RANDOM=$(echo $s1 $s2|/usr/bin/cksum|/usr/bin/cut -b1-8)

# generate a random number up to the total number of files
number=$(($RANDOM % $counter + 1))
echo $number

# print the line number from the file
sed -n "${number}"p ${myfile}


Report Offensive Follow Up For Removal

Response Number 2
Name: lndsey
Date: February 29, 2008 at 06:05:13 Pacific
Subject: send random file (sendmail)
Reply: (edit)
Thanks for your help!
Can you please explain what you are doing there with random generator.

thanks


Report Offensive Follow Up For Removal

Response Number 3
Name: nails
Date: February 29, 2008 at 12:13:14 Pacific
Subject: send random file (sendmail)
Reply: (edit)
RANDOM is a shell environmental variable that each time it is accessed returns a random number between 0 and 32767:

echo $RANDOM
17110

Do a man on ksh for more information.

You can provide your own "seed" for RANDOM which i did with:

RANDOM=$(echo $s1 $s2|/usr/bin/cksum|/usr/bin/cut -b1-8)

I'm paranoid; probably you get by just fine with the default seed.

Next, once I have a total count of lines in the file, dividing the RANDOM number by the total number of lines in the file and looking at the remainder (MODULO):

number=$(($RANDOM % $counter + 1))

returns a number from 1 to the number of total lines - 1. Add 1 or you'll statistically never be able to look at the last line of the file.


Report Offensive Follow Up For Removal




Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: send random file (sendmail)

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




acer 312T BIOS problem

K7 Turbo possible max fsb?

Pc anywher problem

WinFLP & OE/Outlook2003

Computer resets after a few minutes


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC